Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
brentshields
on March 30, 2014
|
parent
|
context
|
favorite
| on:
Class Hierarchies? Don't Do That
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
on March 30, 2014
[–]
Note that GADTs are a bit overkill for this. All you really need is ExistentialQuantification. GADTs are ExistentialQuantification + TypeEqualities.
Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: