Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Fixed Point function
      (Sumit Sahrawat, Maths & Computing, IIT (BHU))


----------------------------------------------------------------------

Message: 1
Date: Tue, 27 Jan 2015 12:52:09 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
        <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Fixed Point function
Message-ID:
        <CAJbEW8NMwztkgbQfSQDrLFPNdgwTuH_=n5-wseomjf7snfc...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Take a look here
<http://bm380.user.srcf.net/cgi-bin/stepeval.cgi?expr=let+fix+f+%3D+f+%28fix+f%29%0D%0A++++fact+%3D+fix+%24+%5Cf+n+-%3E+if+n+%3D%3D+0+then+1+else+n+*+f+%28n+-+1%29%0D%0Ain+fact+4>
.
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 <[email protected]> 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
> 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 (......)
>
>
> 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.
>
> -Karl
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>


-- 
Regards

Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150127/d901e6f1/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 79, Issue 31
*****************************************

Reply via email to