For example, trying to compile the following code
{-# LANGUAGE StandaloneDeriving, KindSignatures, DataKinds, GADTs#-}
data ExprTag = Tag1 | Tag2
data Expr (tag :: ExprTag) where
Con1 :: Int -> Expr tag
Con2 :: Expr tag -> Expr tag
Con3 :: Expr tag -> Expr Tag2
deriving instance Eq (Expr a)
gives a type error
Could not deduce (tag1 ~ tag)
from the context (a ~ 'Tag2)
bound by a pattern with constructor
Con3 :: forall (tag :: ExprTag). Expr tag -> Expr 'Tag2,
in an equation for `=='
at Bar.hs:11:1-29
or from (a ~ 'Tag2)
bound by a pattern with constructor
Con3 :: forall (tag :: ExprTag). Expr tag -> Expr 'Tag2,
in an equation for `=='
at Bar.hs:11:1-29
`tag1' is a rigid type variable bound by
a pattern with constructor
Con3 :: forall (tag :: ExprTag). Expr tag -> Expr 'Tag2,
in an equation for `=='
at Bar.hs:11:1
`tag' is a rigid type variable bound by
a pattern with constructor
Con3 :: forall (tag :: ExprTag). Expr tag -> Expr 'Tag2,
in an equation for `=='
at Bar.hs:11:1
Expected type: Expr tag1
Actual type: Expr tag
In the second argument of `(==)', namely `b1'
In the expression: ((a1 == b1))
When typechecking the code for `=='
in a standalone derived instance for `Eq (Expr a)':
To see the code I am typechecking, use -ddump-deriv
I can see why this doesn't work, but is there some solution that doesn't require me to manually write the Eq (and Ord) instances?
*
kind doesn't make a difference here. You get the same error with plain old phantom types. – Greenburg(Con3 x) == (Con3 y) = ?
Note thatx :: Expr tagX
andy :: Expr tagY
don't even have the same type, so even writing it by hand you can't say something likex == y
because it won't typecheck. – WhitefacedExpr t
to anExpr Tag2
, and then compare for equality. – Noway