I have a couple of classes that form part of a wider hierarchy and I'm trying to implement them on
class StanfordType a where text :: a -> Text class StanfordType a => Dep a where relation :: (StanfordType b) => a -> b data DepTag a b where DepTag :: (StanfordType a) => Text -> a -> DepTag Text a instance StanfordType (DepTag a b) where text (DepTag s _) = s instance Dep (DepTag a b) where relation (DepTag _ r) = r
When I try to compile this, I'm thrown the following error:
• Could not deduce: b ~ b1 from the context: (a ~ Text, N.StanfordType b) bound by a pattern with constructor: DepTag :: forall b. N.StanfordType b => Text -> b -> DepTag Text b, in an equation for ‘relation’ at src/NLP/Data.hs:17:45-54 ‘b’ is a rigid type variable bound by the instance declaration at src/NLP/Data.hs:17:10 ‘b1’ is a rigid type variable bound by the type signature for: relation :: forall b1. N.StanfordType b1 => DepTag a b -> b1 at src/NLP/Data.hs:17:35 • In the expression: r In an equation for ‘relation’: relation (DepTag _ r) = r In the instance declaration for ‘N.Dep (DepTag a b)’ • Relevant bindings include r :: b (bound at src/NLP/Data.hs:17:54) relation :: DepTag a b -> b1 (bound at src/NLP/Data.hs:17:35)
I can't work out why the compiler can't see that both
relation (Dep) and
b in the type signature of
relation are the same. What am I missing here?