[GHC] #13906: ApplicativeDo doesn't handle existentials as well as it could

GHC ghc-devs at haskell.org
Mon Jul 3 08:57:12 UTC 2017


#13906: ApplicativeDo doesn't handle existentials as well as it could
-------------------------------------+-------------------------------------
        Reporter:  dfeuer            |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.4.1
       Component:  Compiler          |              Version:  8.0.1
      Resolution:                    |             Keywords:  ApplicativeDo
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  GHC rejects       |  Unknown/Multiple
  valid program                      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonmar):

 Right, but we only need to ensure that a strict pattern match is bound by
 a `>>=`.  In my example:

 {{{
 do
   T x1 <- a
   x2 <- b x1
   T x2 <- c
   x4 <- d x2
   return (x2,x4)
 }}}

 we can safely translate this to:

 {{{
 (\x2 x4 -> (x2,x4)) <$> (a >>= \(T x1) -> b x1) <*> (c >>= \(T x2) -> d
 x2)
 }}}

 and this has the correct strictness behaviour. I won't write it all out
 here, but I'm sure you can see that if you expand out using `<*> = ap` and
 apply some other laws then you'll get the right sequence of binds here.

 This translation is better (i.e. has lower cost, in the terminology of the
 ApplicativeDo paper) than the one we'd get if we just started by breaking
 up the original sequence at every strict pattern match.

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


More information about the ghc-tickets mailing list