[GHC] #10457: Revise/remove custom mapM implementation for lists

GHC ghc-devs at haskell.org
Mon Jun 1 20:23:55 UTC 2015


#10457: Revise/remove custom mapM implementation for lists
-------------------------------------+-------------------------------------
        Reporter:  dolio             |                   Owner:
            Type:  task              |                  Status:  new
        Priority:  normal            |               Milestone:  7.10.2
       Component:  libraries/base    |                 Version:  7.10.1
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  None/Unknown      |  Unknown/Multiple
      Blocked By:                    |               Test Case:
 Related Tickets:                    |                Blocking:
                                     |  Differential Revisions:  Phab:D924
-------------------------------------+-------------------------------------

Comment (by dolio):

 If I understand correctly, simonmar has a `Monad` whose `Applicative`
 instance does batching of remote calls, because you can do that when you
 use `(<*>)` but not `(>>=)`. So:

 {{{
 f <*> x
 }}}

 does one round trip to the server, while:

 {{{
 f >>= \g -> x >>= \y -> return (g y)
 }}}

 does two.

 The custom `mapM` does n trips, where n is the length of the list, while
 `traverse` does one, because the latter is implemented using:

 {{{
 cons_f x ys = (:) <$> f x <*> ys
 }}}

 whereas the custom one is:

 {{{
 cons_f x ys = do { z <- f x ; zs <- ys ; return (z:zs) }
 }}}

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


More information about the ghc-tickets mailing list