4 ms·
You can use GADTs for this. For example: data Showable where Showable :: Show a => a -> Showable This allows you to create a polymorphic container like
by brentshields 13y ago
You can use GADTs for this. For example:
data Showable where
Showable :: Show a => a -> Showable
This allows you to create a polymorphic container like [Showable 5, Showable "hello"] where the polymorphic type is constrained to be a member of the Show typeclass.
- tel 13y agoNote that GADTs are a bit overkill for this. All you really need is ExistentialQuantification. GADTs are ExistentialQuantification + TypeEqualities.