[GHC] #10892: ApplicativeDo should use *> and <*

GHC ghc-devs at haskell.org
Fri Sep 18 17:22:00 UTC 2015


#10892: ApplicativeDo should use *> and <*
-------------------------------------+-------------------------------------
        Reporter:  simonmar          |                   Owner:  simonmar
            Type:  task              |                  Status:  new
        Priority:  normal            |               Milestone:  8.0.1
       Component:  Compiler          |                 Version:  7.11
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:
-------------------------------------+-------------------------------------

Comment (by ekmett):

 Here's a sketch of how this could work:

 The current patch for `ApplicativeDo` tracks applicative "chains".

 This would modify the `Applicative` chains you have to hold a `Maybe`
 pattern instead of a pattern or you could just check for wildcard
 patterns.

 There are basically 3 cases for dealing with the chain of (<*>)'s we use
 today.

 If you have a prefix of things that don't have meaningful patterns, you
 can bind them with `(*>)`, just like we'd bind with (>>) before.

 {{{
 do foo;bar;baz; x <- quux; y <- quaffle; return (xyzzy x y)

 foo *> bar *> baz *> (xyzzy <$> quux <*> quaffle)
 }}}

 Otherwise, once you've seen a pattern that actually matters, any
 subsequent missing patterns can be dropped by using `(<*)` or `(<$)`.

 The `(<*)` case is mentioned in the description.

 The `(<$)` case happens for

 {{{
 foo = do
    bar
    return whatever
 }}}

 which becomes

 {{{
 foo = whatever <$ bar
 }}}


 This desugaring should then favor all the right things.

 `(*>)` is typically a little cheaper than `(<*)`. `(<$)` and `(*>)` are
 cheaper than `(<$>)` and `(<*>)` when usable.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10892#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list