Re: [Haskell-cafe] how to print out intermediate results in a recursive function?

2012-02-04 Thread MigMit
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 [] =

Re: [Haskell-cafe] how to print out intermediate results in a recursive function?

2012-02-04 Thread Steve Horne
On 04/02/2012 08:46, MigMit wrote: 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

Re: [Haskell-cafe] how to print out intermediate results in a recursive function?

2012-02-04 Thread Roman Cheplyaka
* Steve Horne sh006d3...@blueyonder.co.uk [2012-02-04 11:54:44+] On 04/02/2012 08:46, MigMit wrote: 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

Re: [Haskell-cafe] how to print out intermediate results in a recursive function?

2012-02-04 Thread Brent Yorgey
On Sat, Feb 04, 2012 at 12:23:07PM -0600, Qi Qi wrote: Hello, I have a question;how can I print out the intermediate number lists in a mergesort recursive function like the following one. merge [] ys = ys merge xs [] = xs merge (x:xs) (y:ys) = if x = y then x :

Re: [Haskell-cafe] how to print out intermediate results in a recursive function?

2012-02-04 Thread Qi Qi
Brilliant! That's what I was looking for. Thanks for all the replies. Sometimes, I suspect that Haskell not only makes easier of the hard things for imperative programming languages but also makes harder of some easy things. Roman Cheplyaka r...@ro-che.info writes: * Steve Horne

Re: [Haskell-cafe] how to print out intermediate results in a recursive function?

2012-02-04 Thread Brent Yorgey
On Sun, Feb 05, 2012 at 01:17:31AM -0600, Qi Qi wrote: Brilliant! That's what I was looking for. Thanks for all the replies. Sometimes, I suspect that Haskell not only makes easier of the hard things for imperative programming languages but also makes harder of some easy things. This is

[Haskell-cafe] how to print out intermediate results in a recursive function?

2012-02-03 Thread Qi Qi
Hello, I have a question;how can I print out the intermediate number lists in a mergesort recursive function like the following one. merge [] ys = ys merge xs [] = xs merge (x:xs) (y:ys) = if x = y then x : merge xs (y:ys) else y : merge (x:xs) ys

Re: [Haskell-cafe] how to print out intermediate results in a recursive function?

2012-02-03 Thread Ivan Lazar Miljenovic
On 5 February 2012 05:23, Qi Qi qiqi...@gmail.com wrote: Hello, I have a question;how can I print out the intermediate number lists in a mergesort recursive function like the following one. You can use the (completely evil and shouldn't be used in production code) Debug.Trace module. merge

Re: [Haskell-cafe] how to print out intermediate results in a recursive function?

2012-02-03 Thread yi huang
You can use trace from Debug.Trace, change the code like this: mergesort l = case trace l l of [] - ... [x] - ... (x:xs) - ... On Sun, Feb 5, 2012 at 2:23 AM, Qi Qi qiqi...@gmail.com wrote: Hello, I have a question;how can I print out the intermediate number lists in a mergesort

Re: [Haskell-cafe] how to print out intermediate results in a recursive function?

2012-02-03 Thread Ozgur Akgun
Hi, There is also this nice trick to use Debug.Trace: merge xs ys | trace (show (xs,ys)) False = undefined -- add this as the first case to merge mergesort xs | trace (show xs) False = undefined -- and this as the first case to mergesort HTH, Ozgur