[Haskell-beginners] Heterogeneous Lists

harry voldermort at hotmail.com
Tue May 28 16:00:46 CEST 2013


Brent Yorgey <byorgey <at> seas.upenn.edu> writes:

> On the other hand, if you sincerely want to know why, it is simply
> that this kind of feature does not fit nicely within the space of the
> design decisions that were made when creating Haskell, for example:
> (1) All the elements of a list must have the same type.  (2) A type
> class cannot be used as a type.  (3) Haskell has no subtyping.  And
> there are good reasons behind these decisions as well.  For example,
> subtyping makes type inference nigh impossible.

Yes, (2) is what I don't understand. I recently ran into this with a GUI
application, where I needed to process a list of widgets that were members
of the same typeclass, but I had to wrap them all because they were
different types.

So so rephrase my question, why can't type classes be used as a type? Is
this an implementation issues, or is there a semantic problem with this?
Creating an existential type and packing all the values seems like busy work
which shouldn't be necessary, or at least something that the compiler should
be doing for me.




More information about the Beginners mailing list