[GHC] #10572: Template Haskell does not implicitly quantify types

GHC ghc-devs at haskell.org
Fri Jun 26 04:14:37 UTC 2015


#10572: Template Haskell does not implicitly quantify types
-------------------------------------+-------------------------------------
        Reporter:  spinda            |                   Owner:
            Type:  bug               |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Template Haskell  |                 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:
-------------------------------------+-------------------------------------
Description changed by spinda:

Old description:

> Consider the simple quasiquoter producing a type variable:
>
> {{{
> tv :: QuasiQuoter
> tv = QuasiQuoter { quoteType = varT . mkName }
> }}}
>
> If a type variable is introduced elsewhere in a type signature, it is
> implicitly quantified as normal and the TH name resolves properly:
>
> {{{
> id' :: a -> [tv|a|]
> id' x = x
> }}}
>
> But if the type variable is not mentioned elsewhere in the type, an error
> results:
>
> {{{
> const' :: a -> [tv|b|] -> a
> const' x _ = x
> }}}
>
> {{{
> Not in scope: type variable ‘b’
> }}}
>
> One would expect the type variable introduced by the TH splice to be
> included in the implicit quantification of the type signature.
>
> In fact, there is no way to introduce a new type variable in this
> context, apart from using {{{Rank(2/N)Types}}} with an explicit
> {{{forall}}}. But this prevents the type variable from being referred to
> elsewhere in the type, eg:
>
> {{{
> const'' :: [tv|a|] -> b -> [tv|a|]
> const'' x _ = x
> }}}

New description:

 Consider this simple quasiquoter producing a type variable:

 {{{
 tv :: QuasiQuoter
 tv = QuasiQuoter { quoteType = varT . mkName }
 }}}

 If a type variable is introduced elsewhere in a type signature, it is
 implicitly quantified as normal and the TH name resolves properly:

 {{{
 id' :: a -> [tv|a|]
 id' x = x
 }}}

 But if the type variable is not mentioned elsewhere in the type, an error
 results:

 {{{
 const' :: a -> [tv|b|] -> a
 const' x _ = x
 }}}

 {{{
 Not in scope: type variable ‘b’
 }}}

 One would expect the type variable introduced by the TH splice to be
 included in the implicit quantification of the type signature.

 In fact, there is no way to introduce a new type variable in this context,
 apart from using {{{Rank(2/N)Types}}} with an explicit {{{forall}}}. But
 this prevents the type variable from being referred to elsewhere in the
 type, eg:

 {{{
 const'' :: [tv|a|] -> b -> [tv|a|]
 const'' x _ = x
 }}}

--

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


More information about the ghc-tickets mailing list