[Haskell-beginners] Continuations

David McBride toad3k at gmail.com
Thu May 28 16:58:47 UTC 2015


\k -> k (x + y)

is equivalent to

blah k = k (x + y)

Except for the fact that you have no function name to work with, which is
why it is called an anonymous function (or lambda).  You can use it
anywhere in your code without having to bother create a named function.

On Thu, May 28, 2015 at 9:57 AM, Shishir Srivastava <
shishir.srivastava at gmail.com> wrote:

> Hi,
>
> Reading on continuation I've came across this new style of creating the
> functions which I guess is not very clear in how it works
>
> ---------------
> Prelude> let add_cps x y = \k -> k (x+y)
> Prelude> add_cps 3 4 $ print
> 7
> ---------------
>
> I have some questions as to
> 1) what is the role of variable 'k' and what eventually happens to it.
> 2) How does print work after the $ because there is clearly no parameter
> being passed to it.
>
> Thanks,
> Shishir Srivastava
>
>
> _______________________________________________
> 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/20150528/b39e1533/attachment.html>


More information about the Beginners mailing list