Given:
{-# LANGUAGE TypeFamilies #-}
type family TF1 a
data T1 a
data T2 a
class C a where
type TF2 a
instance (TF1 a ~ T1 b) => C (T2 a) where
type TF2 (T2 a) = b
Compilation fails with the error:
• Type variable ‘b’ is mentioned in the RHS,
but not bound on the LHS of the family instance
• In the type instance declaration for ‘TF2’
In the instance declaration for ‘C (T2 a)’
type TF2 (T2 a) = TF1 a
compiles, evaluating to T1 b
, but I want just b
.
How do acheive what I am trying to do - get a type variable from the result of a type family application? It would seem that I would need some form of ‘type-level pattern match’.