Why is (monad) elegance so costly?
Sat, 3 Nov 2001 14:55:30 +0800 (GMT-8)
I feel embarrased when I post newbie questions after one year
of decent Haskell programming. But it feels much better to ask than to
suffer in ignorance.
My newbie question is: Could anyone explain why the second version of the
following function is better.
Is there a tutorial kind of paper(or related) that gives programmer-view
of closures? In particular when they are created, what do they contain and
where and how they should be avoided to make program faster.
Thank you very much,
> You can see what is going on if you give the flag -ddump-simpl
> to GHC, and then look for the function Main.eval. You'll see
> that eval has a shape like
> eval (Var x) = let ... in \env -> ...
> eval (Add u v) = let ... in \env -> ...
> This is bad, because eval is building a function closure for
> the \env, instead of taking its two arguments together as does
> simplEval. We'd prefer
> eval (Var x) env = let ... in ...
> eval (Add u v) env = let .. in ...