Skip to content

Add 'pattern TypeRep :: () => Typeable a => TypeRep a' to Type.Reflection

Type.Reflection should export a TypeRep pattern synonym akin to pattern Sing from singletons, that brings a local Typeable a constraint into scope by pattern matching:

type TypeableInstance :: forall k. k -> Type
data TypeableInstance a where
 TypeableInstance :: Typeable a => TypeableInstance a

typeableInstance :: forall (k :: Type) (a :: k). TypeRep a -> TypeableInstance a
typeableInstance typeRep = withTypeable typeRep TypeableInstance

pattern TypeRep :: forall (k :: Type) (a :: k). () => Typeable a => TypeRep a
pattern TypeRep <- (typeableInstance -> TypeableInstance)
  where TypeRep = typeRep

Relevant to this question: What's the modern way to apply a polymorphic function to a Dynamic value in GHC 8.8 and onwards? (reddit) where the answer would be

apD :: Typeable f => (forall a. a -> f a) -> Dynamic -> Dynamic
apD f (Dynamic TypeRep a) = Dynamic TypeRep (f a)

This is a much nicer interface than continuation passing style with withTypeable.

I always forget where these proposals should go so please direct me to the proper venue. Thank you.

Edited by Icelandjack
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information