On 26 Apr 2000, Friedrich Dominicus wrote:
> This question may sound a bit strange. I'll try to explain. I have
> written a piece of Haskell and found that I did not understand
> things. I tried to look what I got wrong and searched for a
> possibility to give me output. Now obvious is that Haskell has not
> debugger so I was thinking helping myself with adding some simple
> output stuff but that did not seem to work either. So guess I have
>
> sum:: [Int] -> Int
> sum [] = 0
> sum (x:xs) = ....
>
> Now how can I do the following print the actual sum in every step and
> how to see e.g what x or xs is on this step?
>
> I tried it with simple ouput but did not get it right.
>
> Any suggestions?
> Friedrich
>
import IOExts
sum:: [Int] -> Int
sum [] = 0
sum (x:xs) = trace (show (x:xs) ++ "\n") ....
Note, this is an unpure extension to haskell that should be used for
debugging purposes only. It can sometimes be very hard to interpret the
output since it will be produced in the order the expressions are
evaluated.
Anyway, it is sometimes useful.
/Lars L