[GHC] #15833: Typed template haskell quote fails to typecheck when spliced due to an ambiguous type variable

GHC ghc-devs at haskell.org
Tue Oct 30 11:18:56 UTC 2018


#15833: Typed template haskell quote fails to typecheck when spliced due to an
ambiguous type variable
-------------------------------------+-------------------------------------
        Reporter:  mpickering        |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.6.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by mpickering):

 If I inline both recursive calls to `execOp` then the code in `Compiler`
 fails to typecheck.

 {{{
  26 execOp :: Monoid m => Operator -> QTExp (IO m) -> QTExp (IO m)
  27 execOp op yld =
  28   case op of
  29     Scan ->
  30       while [|| \r -> ($$(yld) >> r)||]
  31     Join left right ->
  32       while [|| \r -> $$(while [|| \r -> ($$(yld) >> r) ||]) >> r ||]
 }}}

 {{{
 Compiler.hs:32:26: error:
     • Could not deduce (Monoid a0) arising from a use of ‘while’
       from the context: Monoid m
         bound by the type signature for:
                    execOp :: forall m.
                              Monoid m =>
                              Operator -> QTExp (IO m) -> QTExp (IO m)
         at Compiler.hs:26:1-62
       The type variable ‘a0’ is ambiguous
       These potential instances exist:
         instance Monoid a => Monoid (IO a) -- Defined in ‘GHC.Base’
         instance Monoid Ordering -- Defined in ‘GHC.Base’
         instance Semigroup a => Monoid (Maybe a) -- Defined in ‘GHC.Base’
         ...plus 7 others
         (use -fprint-potential-instances to see them all)
     • In the expression: while [|| \ r -> ($$(yld) >> r) ||]
       In the Template Haskell splice
         $$(while [|| \ r -> ($$(yld) >> r) ||])
       In the first argument of ‘(>>)’, namely
         ‘$$(while [|| \ r -> ($$(yld) >> r) ||])’
    |
 32 |       while [|| \r -> $$(while [|| \r -> ($$(yld) >> r) ||]) >> r ||]
    |
 }}}

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


More information about the ghc-tickets mailing list