withDict and casts
This works:
{-# LANGUAGE TypeFamilies #-}
module M where
import GHC.Exts
import Type.Reflection
type family Id x
type instance Id x = x
cast :: forall a. TypeRep a -> (Typeable a => Int) -> Int
cast = withDict @(TypeRep a) @(Typeable a)
If I replace the type of cast
with
cast :: forall a. Id (TypeRep a) -> (Typeable a => Int) -> Int
I get an error:
Invalid instantiation of ‘withDict’ at type:
Id (TypeRep a) -> (Typeable a -> Int) -> Int
Two problems:
(1) I understand withDict
might not work with casts, but this code is explicitly passing type arguments to withDict
. See also #19915 / #20000.
(2) Typeable a ->
in the error message should be Typeable a =>
.