I am a beginner in Haskell who has a background in imperative languages, and I wanted to know if it was possible to print in a Haskell function and not print in the main.
merge :: Ord a => [a] -> [a] -> [a]
merge [] ys = ys
merge xs [] = xs
merge (x:xs) (y:ys)
| x < y = x:(merge xs (y:ys))
| otherwise = y:(merge (x:xs) ys)
I wanted to see the list's contents after every merge operation, but an error occurs when I tried inserting a print statement in this function. This code is part of a program that does a merge sort operation, so I cannot place a print statement in the main function. I would use the ghci, and compile the merge function from a separate file to manually see how the merge function works, but I became curious if it was possible to see the list's contents in the merge function itself.
How would I show the contents of the list given this merge function? Do I need to recode the whole merge function in another way to see the contents of the list? If so, how would it look like?