[Haskell-cafe] Curry and Reader monad

Julian Blake Kongslie jblake at omgwallhack.org
Thu May 7 20:02:15 EDT 2009

On Thu, 2009-05-07 at 16:45 -0700, Daryoush Mehrtash wrote:
> In the  Is currying monadic? post the author says:
>         This is again a nested expression. So I wondered if you could
>         again "flatten" it with a monadic do block: 
>         let add3 = do
>                 a <- get first parameter
>                 b <- get second parameter
>                 c <- get third parameter
>                 return a+b+c
>         OK, so I "know" that functions in Haskell (which uses currying
>         for functions as a general rule) are the "Reader monad". But I
>         don't understand it well enough to know if that means you can
>         use Reader to implement the above... 
>         (I don't understand Reader at all in fact. I must bang my head
>         against it again, but I find it very confusing - how the monad
>         is represented, what the functions are, and how they get
>         magically applied.) 
> Any idea what he is talking about?

A function of a single argument can be represented as a Reader monad,
but Reader doesn't really do the currying action. It provides "ask"
which is essentially "get first parameter". For multiple parameters,
you'd be nesting Readers.

If he's asking for a "get next parameter" operation, then you need to
track the concept of "next", which implies some sort of state or
indexing. An indexed monad in particular is highly appropriate for the
"currying monad", as what he's asking for is essentially a session type.

> Thanks
> Daryoush

-Julian Blake Kongslie 
If this is a mailing list, please CC me on replies.

vim: set ft=text :
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090507/1e3ef3cc/attachment.bin

More information about the Haskell-Cafe mailing list