
On Jul 21, 2011 5:28 AM, "Thomas"
Hi Felipe, David!
It works!!! :-)
What I do not really understand, however, is the difference between
eval_begin n k = eval n (if (n< 0) then k else (BeginCont k (n - 1))) and
eval_begin n k = if (n< 0) then eval n k else eval n (BeginCont k (n -
1))
The difference comes down to two things: 1. The type of 'if'. The haskell 'if ... then ... else ...' is conceptually just a function with the type (Bool -> a -> a -> a). The two branches must be of the same type. 2. In the code:
f (if p then a else b)
If somehow the 'if' could type-check with 'a' and 'b' being of different types, the compiler wouldn't know which type to pick for 'f'. In Haskell, we're not allowed to delay type-checking until run-time - the compiler demands that it can solve everything before running any of it. I hope I haven't confused things even more! Antoine