Template Haskell: newName not new enough
When I compile this:
{-# LANGUAGE TemplateHaskell, PolyKinds, DataKinds #-}
{-# OPTIONS_GHC -Wall #-}
import Language.Haskell.TH
$( do TyConI (DataD _ _ [PlainTV tvb_a] _ _) <- reify ''Maybe
my_a <- newName "a"
return [TySynD (mkName "SMaybe") [KindedTV my_a (AppT (ConT ''Maybe) (VarT tvb_a))]
(TupleT 0)] )
I get this:
/Users/rae/temp/Bug.hs:6:4: Warning:
This binding for ‛a’ shadows the existing binding
bound at /Users/rae/temp/Bug.hs:6:4
The problem is that, in the library definition for Maybe
, the name of its type variable is a
. In my Template Haskell code, I read in Maybe
's definition (using reify
) to extract the name of Maybe
's type variable. I then create a new name, also seeded with "a"
. Then, I create a type synonym definition
type SMaybe (a_newName :: Maybe a_Maybe) = ()
where a_newName
is the variable I newName
d, and a_Maybe
is the name I slurped from Maybe
's definition. These variables print with different uniques, but the warning comes up anyway.
This problem actually came up in real code (singletons library), where I'm trying to get the generated code to be warning-free.
This was tested on 7.7.20131031.
Trac metadata
Trac field | Value |
---|---|
Version | 7.7 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Template Haskell |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |