[Haskell-beginners] Fixed Point function

Animesh Saxena animeshsaxena at icloud.com
Tue Jan 27 04:43:00 UTC 2015


I stumbled across this example as a shiny way of explaining why Lazy eval matters....

    fact = fix $ \f n -> if n == 0 then 1 else n * f (n-1)
fix f = f (fix f)

With lazy eval, I get 

fact 4 = fix $ \f 4 (......)
since haskell goes outside to inside I have,

fac 4 = $ \f 4 (......) (fix $ \f 4 (......))
Now the first chunk can get evaluated, but what about the rest of the expression. The outer "f" from "fix f" function has the parameter (fix f). So when writing "f (fix f)" apparently f got evaluated without using this parameter. I understand that the anonymous lambda does have 4 as the param, but somehow "f (fix f)" doesn't feel complete. 

-Animesh


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150127/81d18119/attachment.html>


More information about the Beginners mailing list