[clean-list] About semantic restrictions on type classes.

Sjaak Smetsers sjakie@cs.kun.nl
Thu, 23 Jan 2003 12:41:10 +0100


Dear Fabian,

>In §6.11 of the Clean Language Report 2.1, it is said that :
>
>         A type instance of an overloaded type must be a  flat type , i.e. a
>type of the form T a1...an where ai are type variables which are  all
>different.

In Clean we have the same restriction on instance types as in Haskell. I 
don't know whether this restriction is fundamental, what i do know is that 
the current implementation of Clean cannot be extended (easily) in such a 
way that it can deal with 'overlapping' instance types.

>supposing I have the following :
>
>class k x y :: x y -> y
>
>The above-mentionned restriction prevents the definition of :
>
>instance k x ( t x )
>
>where t is some type constructor.
>
>Now, if the class k is instead defined as follows :
>
>class k x t y :: x ( t y ) -> t y
>
>I can write :
>
>instance k x t y.

So what?

In the first case your (illegal) instance would have type

x ( t x ) -> ( t x )

whereas in the second case it has type

  x ( t y ) -> t y

Two different instances, so what are you trying to illustrate?

>That is, using type-constructor classes may provide in some cases a
>workaround to the limitations imposed by the 'flat type' semantic
>restriction above.

I don't see your point.

Regards,

Sjaak Smetsers