[Haskell-cafe] Is there a way to see the equation reduction?

Daryoush Mehrtash dmehrtash at gmail.com
Tue Mar 31 23:02:29 EDT 2009

I am interested in reasoning about a code,  say for example:

data DList a = DLNode (DList a) a (DList a)

mkDList :: [a] -> DList a

mkDList [] = error
"must have at least one element"
mkDList xs = let (first,last
= go last <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:last>
xs first
             in  first

  where go :: DList a -> [a] -> DList a -> (DList a, DList a)
        go prev []     next = (next,prev)
        go prev (x:xs) next = let this        = DLNode prev x rest
= go this xs next

                              in  (this,last

takeF :: Integer
-> DList a -> [a]
takeF 0     _                 = []
takeF (n+1) (DLNode _ x next) = x : (takeF n next)

With the debugger I can see the calls that are made when I run:

takeF 2 (mkDList [1,2,3])

But I am more interested in seeing the expansion and reduction that
the execution encounters as it lazily evaluates the function.


On Tue, Mar 31, 2009 at 6:49 PM, Bernie Pope <florbitous at gmail.com> wrote:

> 2009/4/1 Daryoush Mehrtash <dmehrtash at gmail.com>
>> I am trying to write out the execution of the recursive calls in mkDList
>> example<http:/http://www.haskell.org/haskellwiki/Tying_the_Knot/www.haskell.org/haskellwiki/Tying_the_Knot>for different size lists.  Is there a way in ghc, or ghci where for a given
>> list I can see the intermediate recursive and evaluation steps?
> Have you tried stepping through the code using the GHCi debugger?
> http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html
> If you have tried, but it didn't satisfy your needs, could you explain what
> is lacking?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090331/1f112add/attachment.htm

More information about the Haskell-Cafe mailing list