Desugaring do-notation to Applicative
Simon Peyton-Jones
simonpj
Tue Oct 1 13:49:40 UTC 2013
What happens when there are some monad things that precede the applicative bit:
do { x <- e1
; y <- e2[x]
; z <- e3[x]
; h[y]
... }
does this convert to
do { x <- e1
; (y,z) <- (,) <$> e1 <*> e2
; h[y]
...
I assume so, but it would be good to say.
Also worth noting that join can be used to eliminate the tuple in arbitrary contexts, not only ones that end in return. Eg in the above example we can desugar to
e1 >>= \x ->
join (\y z -> do { h[y]; ... })
e2 e3
I think. Again worth documenting if so.
I don't know whether the tuple-version or join-version would be more optimisation friendly.
Simon
| -----Original Message-----
| From: Glasgow-haskell-users [mailto:glasgow-haskell-users-
| bounces at haskell.org] On Behalf Of Simon Marlow
| Sent: 01 October 2013 13:40
| To: glasgow-haskell-users
| Subject: Desugaring do-notation to Applicative
|
| Following a couple of discussions at ICFP I've put together a proposal
| for desugaring do-notation to Applicative:
|
| http://ghc.haskell.org/trac/ghc/wiki/ApplicativeDo
|
| I plan to implement this following the addition of Applicative as a
| superclass of Monad, which is due to take place shortly after the 7.8
| branch is cut.
|
| Please discuss here, and I'll update the wiki page as necessary.
|
| Cheers,
| Simon
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
More information about the Glasgow-haskell-users
mailing list