Not sure how to name this question, so the title may be misleading. The question is clear I think: let’s say you have a datatype like
data TRep a where
TInt :: TRep Int
TList :: TRep a -> TRep [a]
TFun :: TRep a -> TRep b -> TRep (a -> b)
Is there a way to “autoderive” a function like
decideConstr :: forall c a. Typeable c => TRep a -> Maybe (Dict (c a))
Currently I need to implement it for every “interesting” constraint, like
decideEq :: TRep a -> Maybe (Dict (Eq a))
decideEq TInt = pure Dict
decideEq (TList a) = do
Dict <- decideEq a
pure Dict
decideEq (TFun _a _b) = empty
and so on (obviously I have many more representable types, so it’s a very annoying copypaste exercise). Is there any existing library that deals with it? I understand it can be tad complicated, as it’s not a matter of simply lifting Dict
from all cases (like in the Eq
function example).