[Haskell-beginners] Fixed Point function
Sumit Sahrawat, Maths & Computing, IIT (BHU)
sumit.sahrawat.apm13 at iitbhu.ac.in
Tue Jan 27 07:22:09 UTC 2015
Take a look here
The above webpage uses stepval <https://github.com/bmillwood/stepeval>, it
can evaluate any expression step by step using equational reasoning.
On 27 January 2015 at 11:54, Karl Voelker <karl at karlv.net> wrote:
> On Mon, Jan 26, 2015, at 08:43 PM, Animesh Saxena wrote:
> I stumbled across this example as a shiny way of explaining why Lazy eval
> 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 (......)
> Not quite. Let's go one step at a time:
> fact 4 = (fix $ \f n -> if n == 0 then 1 else n * f (n - 1)) 4
> Now we can bring in the definition of fix, substituting the argument to
> fix for all of the occurrences of f in the definition of fix. Notice that
> we can't substitute the 4 for n yet.
> fact 4 = ((\f n -> if n == 0 then 1 else n * f (n - 1)) (fix $ \f n -> if
> n == 0 then 1 else n * f (n - 1))) 4
> I think if you are very patient and methodical about performing the
> substitutions (and writing them out fully - no dot-dot-dot), then you'll
> figure out how it all works.
> Beginners mailing list
> Beginners at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners