Using existential types

Graham Klyne GK at ninebynine.org
Fri Oct 10 10:40:00 EDT 2003


At 22:48 09/10/03 -0400, Derek Elkins wrote:
>As always, the wiki has some remarks about this,
>http://www.haskell.org/hawiki/ExistentialTypes.

Thanks for the reminder :-)

Interestingly, when I read this:
[[
However this won't work since the elements of the list can be of SEVERAL 
different types (like a sphere and a polygon and a mesh etc. etc.) but 
lists need to have elements of the same type.
]]

I was reminded of very similar issues I encountered in my own development, 
which for the most part I resolved without using existential types.

Originally, I had contemplated using type classes, so that (w.r.t. the 
above example) spheres and polygons would be different types that are 
instances of a common class.  That's how we do it with OOP, right?  But it 
falls foul of exactly the point made here -- you can't mix the types in 
(say) a list.

It never occurred to me that existential types might be the appropriate 
appoach here.

Instead, I replace the class instances by a single algebraic data type, 
whose members are functions corresponding to OO-style class methods.

#g
--


------------
Graham Klyne
GK at NineByNine.org



More information about the Haskell-Cafe mailing list