<div dir="ltr">Thanks! Since I studied lambda calc a bit I understand the steps<div><br></div><div>(\message -> message 6) (\foz -> foz)<br>(\foz -> foz) 6<br> 6<br></div><div><br></div><div>But this is so bizarre! To have a "constructor" that creates an instance, which is then really a holder of a lambda calculation is a mind-bender.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Dec 29, 2020 at 4:07 PM Francesco Ariis <<a href="mailto:fa-ml@ariis.it">fa-ml@ariis.it</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Il 29 dicembre 2020 alle 15:43 Lawrence Bottorff ha scritto:<br>
> Okay, I'm in Lesson 10 of *Get Programming with Haskell * and we're<br>
> creating an OOP-like world with closures. The first step is a cup object<br>
> with one attribute, its ounce size. Here's a "constructor"<br>
> <br>
> cup :: t1 -> (t1 -> t2) -> t2<br>
> cup flOz = \message -> message flOz<br>
> <br>
> so this returns upon use<br>
> <br>
> > myCup = cup 6<br>
> <br>
> myCup which has "internally" a lambda function<br>
> <br>
> (\message -> message) 6<br>
> <br>
> waiting, correct?<br>
<br>
Not exactly. `myCup` is a function with takes another function as input<br>
<br>
    λ> :t myCup<br>
    myCup :: (Integer -> t2) -> t2<br>
<br>
and the body looks like this<br>
<br>
    \f -> f 6<br>
<br>
`\f -> f 6`  is different from  `(\f -> f) 6`!<br>
<br>
<br>
> Now a "method"<br>
> <br>
> getOz aCup = aCup (\foz -> foz)<br>
> <br>
> creates a closure on the lambda function (\foz -> foz) . So upon calling<br>
> <br>
> > getOz myCup<br>
> 6<br>
> <br>
> I'm guessing myCup (\foz -> foz) was evaluated, but I don't understand how<br>
> the 6 that went in as the bound variable in the constructor came out again<br>
> with getOz.<br>
<br>
To recap, `myCup` expands to:<br>
<br>
    myCup<br>
    cup 6<br>
    \message -> message 6<br>
<br>
Now, applying `getOz` to it…<br>
<br>
    getOz myCup<br>
    myCup (\foz -> foz)<br>
    (\message -> message 6) (\foz -> foz)<br>
    (\foz -> foz) 6<br>
    6<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>