ApplicativeDo transformation

Authored by simonmar.

Description

ApplicativeDo transformation

Summary:
This is an implementation of the ApplicativeDo proposal. See the Note
[ApplicativeDo] in RnExpr for details on the current implementation,
and the wiki page https://ghc.haskell.org/trac/ghc/wiki/ApplicativeDo
for design notes.

Test Plan: validate

Reviewers: simonpj, goldfire, austin

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D729

ekmett added a subscriber: ekmett.Sep 17 2015, 6:00 PM

Would it be possible to tweak the generation to use (<*) or (*>) where appropriate when the result isn't being used?

For many Applicatives this can be a massive asymptotic win in terms of sharing and/or computational cost.

ekmett added a comment.EditedSep 17 2015, 6:03 PM

When desugaring using (<*) you'd just omit any handling of the unused result instead.

(\x y -> ...) <$> foo <* bar <*> baz

corresponds to

do x <- foo
   bar
   y <- baz
   return ...

When you discard the result of the first thing you'd use (<$).

... <$ foo

corresponds to

do x <- foo
   return ...