[Haskell] concurrent haskell, higher-order types and parameterizing by typeclass

Sebastian Sylvan sylvan at dtek.chalmers.se
Wed Apr 14 01:28:05 EDT 2004

Abraham Egnor wrote:

> However, this solution requires a new wrapper datatype (or at least a
> new constructor) to be defined for every typeclass to be used in
> Chan-based communication; furthermore, all of the datatypes will be
> identical except for the name of the typeclass.  It seems like I
> should be able to create a type that's parameterized by typeclass,
> i.e. something like:
> data Wrapper c = forall a. c a => Wrapper a
> writer :: Chan (Wrapper Show) -> IO ()
> ...

Ah yes, well that won't work since c is supposed to be a type and Show 
is a type class. And if types could be refered to by type classes for 
which they have an instance, the problem would be solved!

However I agree that Haskell desparately needs this sort of thing. If I 
want to have a list of "Showable" values that should be allowed. 
Moreover I don't even think the programmer should have to "wrap it up" 
inside a "Showable" data type to use it either. A value such as 
[1,"hello",("hello",12)] should automatically be allowed, and the type 
should be inferred by simply taking the intersection of all of the type 
classes for which each element has an instance. Some new syntax might be 
required to group several type classes into one type, perhaps. The 
"type" of a several type classes could be something like ":Show:Eq:" and 
":Show:Ord:Num:". That should then be valid to use in the same manner as 
any other type (list of, tuples etc.). One exception though! A 
"type-class-type" shouldn't be able to be an instance of a type class 
(that could surely lead to some very weird behaviour)!

I'm sure this has been brought up to discussion several times before 
though (although I have missed it).

I really do think this should be a standard feature in Haskell. Yes you 
can get the same functionality by using existential types, but as the 
orignal poster noted it gets tedious very fast, and it's such a common 
feature for programming languages that I don't see why Haskell doesn't 
have it.

/Sebastian Sylvan

Clothes make the man. Naked people have little or no influence on society.
- Mark Twain

More information about the Haskell mailing list