[Haskell-cafe] Tracer for Haskell showing substitutions

Ulrik Rasmussen haskell at utr.dk
Tue Feb 2 10:03:42 EST 2010


Hi all,

I was wondering if someone has written a tracer/debugger that shows you
how a given Haskell expression is evaluated, by generating all the
intermediate states of the expression until it is in normal form?

For instance, given the following code:

> take' 0 xs = []
> take' n (x:xs) = x : take' (n-1) xs
> exp = take' 2 [1,2,3,4,5,6]

the trace of 'exp' would generate something like this:

> exp = take' 2 [1,2,3,4,5,6]
> exp = (\n (x:xs) -> x : take' (n-1) xs) 2 [1,2,3,4,5,6]
> exp = 1 : take' (2-1) [2,3,4,5,6]
> exp = 1 : take' 1 [2,3,4,5,6]
> exp = 1 : (\n (x:xs) -> x : take' (n-1) xs) 1 [2,3,4,5,6]
> exp = 1 : 2 : take' (1-1) [3,4,5,6]
> exp = 1 : 2 : take' 0 [3,4,5,6]
> exp = 1 : 2 : (\0 xs -> []) 0 [3,4,5,6]
> exp = 1 : 2 : []
> exp = [1,2]

That is, all the substitutions performed when evaluating 'exp' from left
to right.

I was thinking that something like this could be rather useful when
teaching or learning Haskell.


Thanks,

Ulrik


More information about the Haskell-Cafe mailing list