[Haskell-beginners] Confusion over currying, , lambda, and closures

Joel Neely joel.neely at gmail.com
Thu Dec 24 12:12:08 UTC 2020


Hi, Lawrence,

Would it help you to think of addB as a function that takes its argument x
and returns a function/lambda that adds x to the argument to which that
returned function is applied?

Best wishes,
-jn-

On Wed, Dec 23, 2020 at 9:12 PM Lawrence Bottorff <borgauf at gmail.com> wrote:

> I have these three versions of addition
>
> addA x y = x + y
> addB x = \y -> x + y
> addC = \x -> \y -> x + y
>
> and all three add two arguments just fine
>
> > addA 2 3
> 5
> > addB 2 3
> 5
> > addC 2 3
> 5
>
> but I can't see how addB and addC are actually accomplishing this. addA is
> currying, which I don't fully follow. addC I understand beta reduction-wise
>
> (\x -> \y -> x + y) 2 3
> (\y -> 2 + y) 3
> (2 + 3)
> 5
>
> but I don't understand addB and what steps are happening currying/beta
> reduction-wise. Can someone break down the steps with addA and addB?
>
> LB
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20201224/a844acc1/attachment.html>


More information about the Beginners mailing list