Open conal opened 10 years ago
I also need to find what the associated type is for a given type function and argument. I'll ask on the ghc-devs list.
Heard from Richard Eisenberg about "Constructing coercions for associated type":
Richard Eisenberg said
Does
FamInstEnv.normaliseType
work for you?FamInstEnv
is in the types/ directory.FamInst.tcGetFamInstEnvs
may also be helpful. FamInst is in the typecheck/ directory.
Looks like just the thing. I may give it a try myself when the issue pops up again if no one beats me to it.
To construct the FamInstEnvs
argument you need, you can do:
normaliseTypeT :: (HasModGuts m, HasHscEnv m) => Role -> Transform c m Type (Coercion, Type)
normaliseTypeT r = do
envs <- constT $ do
guts <- getModGuts
eps <- getHscEnv >>= liftIO . hscEPS
return (eps_fam_inst_env eps, mg_fam_inst_env guts)
arr (normaliseType envs r)
Thanks! I think I'll give it a try.
Are there any mechanisms for constructing coercions for associated type instances? For instance, I have a class:
and an instance
where
Now I want to find/construct a coercion from
Encode (Bool -> Bool)
toEncode Bool -> Encode Bool
that I can then use in aCast
.