some way to reverse engineer lambda expressions out of the debugger?

I am a newbie learning haskell. (First forum post.) I am wondering if there is a trick to get debugging information about functions out of the environment (which for me, for now, is ghci). In this example, *UnixTools> :t map (*) [1,2] map (*) [1,2] :: (Num a) => [a -> a] This is very nice, but I would *really* like to see something like *UnixTools> explodeLambda( map (*) [1,2] ) [(\x -> 1*x),(\x -> 2*x)] Yes, maybe I'm dreaming, but I would like haskell to reverse engineer / pretty print lambda expressions for me. (Note that: *UnixTools> map ($ 5 ) [(\x -> 1*x),(\x -> 2*x)] [5,10] *UnixTools> map ($ 5) ( map (*) [1..2] ) [5,10] So these expressions really are the same, only it could be argued that the first expression is in some sense easier to read if you are debugging something complex. ) I would like to have something like "Data::Dumper" from perl, but of course, on steroids. Is something like this possible, or be worked on? Or probably never going to happen? Cheers, thomas. -- View this message in context: http://www.nabble.com/some-way-to-reverse-engineer-lambda-expressions-out-of... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

tphyahoo:
I am a newbie learning haskell. (First forum post.)
I am wondering if there is a trick to get debugging information about functions out of the environment (which for me, for now, is ghci).
In this example,
*UnixTools> :t map (*) [1,2] map (*) [1,2] :: (Num a) => [a -> a]
This is very nice, but I would *really* like to see something like
*UnixTools> explodeLambda( map (*) [1,2] ) [(\x -> 1*x),(\x -> 2*x)]
Yes, maybe I'm dreaming, but I would like haskell to reverse engineer / pretty print lambda expressions for me.
You can use 'hat' to trace/reduce expressions. http://www.cs.york.ac.uk/fp/hat/ The new ghci debugger can print closures too, but I'm not sure if it does what you want. All very possible, maybe a little experimental though. -- Don

Hello tphyahoo, Saturday, December 30, 2006, 11:53:53 AM, you wrote:
*UnixTools> explodeLambda( map (*) [1,2] ) [(\x ->> 1*x),(\x -> 2*x)]
i'm wondering whether it's possible to use typeclasses to implement this, like packages for symbolic computations (afair, it was demonstrated by Oleg) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Bulat Ziganshin
tphyahoo wrote:
*UnixTools> explodeLambda( map (*) [1,2] ) [(\x ->> 1*x),(\x -> 2*x)]
Have a play with this, from Claus Reinke: http://www.cs.kent.ac.uk/people/staff/cr3/toolbox/haskell/R.hs Regards, Malcolm

Looks very nice!
However, I'm doing my learning on ghci and got an error when I tried to load it.
Is this hugs only, or should I try harder?
2007/1/11, Malcolm Wallace
Bulat Ziganshin
wrote: tphyahoo wrote:
*UnixTools> explodeLambda( map (*) [1,2] ) [(\x ->> 1*x),(\x -> 2*x)]
Have a play with this, from Claus Reinke: http://www.cs.kent.ac.uk/people/staff/cr3/toolbox/haskell/R.hs
Regards, Malcolm _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Looks very nice!
thanks!-) it is far from a full-blown solution to the question in the subject, but it has its uses.
However, I'm doing my learning on ghci and got an error when I tried to load it.
Is this hugs only, or should I try harder?
I was using Hugs when I wrote that, but it works in GHC almost as well. the error message really ought to point to the option needed, which is -fglasgow-exts if you don't want to set the options by hand, just add the following pragma to the top of R.hs: {-# OPTIONS_GHC -fglasgow-exts #-} more annoying is that ghci will ignore the default directive, so you'll need to give explicit types when you want representations: *Main> foldr (+) 0 [1..4] 10 *Main> foldr (+) 0 [1..4] :: R Int (1 + (2 + (3 + (4 + 0)))) *Main> map (*) [1,2] <interactive>:1:0: No instance for (Show (t -> t)) arising from use of `print' at <interactive>:1:0-12 Possible fix: add an instance declaration for (Show (t -> t)) In the call (print it) In the expression: print it In a 'do' expression: print it *Main> map (*) [1,2] :: [R Int -> R Int] [\x->(1 * x),\x->(2 * x)] claus
2007/1/11, Malcolm Wallace
: Bulat Ziganshin
wrote: tphyahoo wrote:
*UnixTools> explodeLambda( map (*) [1,2] ) [(\x ->> 1*x),(\x -> 2*x)]
Have a play with this, from Claus Reinke: http://www.cs.kent.ac.uk/people/staff/cr3/toolbox/haskell/R.hs
Regards, Malcolm _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

works like a charm :)
2007/1/11, Claus Reinke
Looks very nice!
thanks!-)
it is far from a full-blown solution to the question in the subject, but it has its uses.
However, I'm doing my learning on ghci and got an error when I tried to load it.
Is this hugs only, or should I try harder?
I was using Hugs when I wrote that, but it works in GHC almost as well. the error message really ought to point to the option needed, which is -fglasgow-exts
if you don't want to set the options by hand, just add the following pragma to the top of R.hs:
{-# OPTIONS_GHC -fglasgow-exts #-}
more annoying is that ghci will ignore the default directive, so you'll need to give explicit types when you want representations:
*Main> foldr (+) 0 [1..4] 10 *Main> foldr (+) 0 [1..4] :: R Int (1 + (2 + (3 + (4 + 0)))) *Main> map (*) [1,2]
<interactive>:1:0: No instance for (Show (t -> t)) arising from use of `print' at <interactive>:1:0-12 Possible fix: add an instance declaration for (Show (t -> t)) In the call (print it) In the expression: print it In a 'do' expression: print it *Main> map (*) [1,2] :: [R Int -> R Int] [\x->(1 * x),\x->(2 * x)]
claus
2007/1/11, Malcolm Wallace
: Bulat Ziganshin
wrote: tphyahoo wrote:
*UnixTools> explodeLambda( map (*) [1,2] ) [(\x ->> 1*x),(\x -> 2*x)]
Have a play with this, from Claus Reinke: http://www.cs.kent.ac.uk/people/staff/cr3/toolbox/haskell/R.hs
Regards, Malcolm _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (6)
-
Bulat Ziganshin
-
Claus Reinke
-
dons@cse.unsw.edu.au
-
Malcolm Wallace
-
Thomas Hartman
-
tphyahoo