
4 Feb
2012
4 Feb
'12
11:54 a.m.
Well, if you want that in production, not for debugging purposes, you should change the type signature of mergesort so that it uses some monad. Printing requires IO monad; however, I would advise to collect all intermediate results using Writer monad, and print them afterwards:
mergesort [] = return [] mergesort [x] = return [x] mergesort xs = do tell [xs] -- that's right, "[xs]", not "xs" let (as, bs) = splitAt (length xs `quot` 2) xs liftM2 merge (mergesort as) (mergesort bs) Also, don't forget that IO actions are values too. IOW, your list of intermediate results can be a list of IO actions, effectively deferring
On 04/02/2012 08:46, MigMit wrote: their "execution" until later.