Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Note that GADTs are a bit overkill for this. All you really need is ExistentialQuantification. GADTs are ExistentialQuantification + TypeEqualities.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: