Hi all,
I’ve a question about the status of Typeable
in PureScript.
What I like to do is check at runtime that the type of a container I have and the type of input from the user are equal. A simplified version in Haskell using GADTs where the type a
in Input
is existential:
data Container :: Type -> Type where
Elem :: Typeable a => a -> Container a
-- more omitted --
data Input :: Type where
Change :: Typeable a => a -> Input
-- more omitted --
During runtime using eqT
and :~:
:
handle :: formal a. Container a -> Input -> Container a
handle (Elem old_val) (Change new_val)
-- this is allowed because the compiler now knows
-- `old_val` and `new_val` have the same type due to matching on `Refl`
| Just Refl <- sameT old_val new_val = Edit new_val
| otherwise = Edit old_val
where
sameT :: ( Typeable a, Typeable b ) => a -> b -> Maybe (a :~: b)
sameT _ _ = eqT
I’ve found this old library, which doesn’t work any more. Also, I’ve found this GitHub issue talking about automatically generating Typeable
instances by the compiler. It mentions that “it’s almost always a nice idea to explore alternatives to Typeable
.” However, it doesn’t mention any.
Is there some alternative I could use? Should I revive Typeable
?