[clean-list] uniqueness question

John van Groningen johnvg at cs.ru.nl
Mon Nov 16 17:55:53 MET 2009


Edsko de Vries wrote:
>While all of that is true, it still does not explain why all occurrences of a type variable need the same attribute. For instance, there is absolutely no problem with
>
>second :: *a .a -> *a
>second x y = x

I think you are right, but I am not expert in type systems. I also
don't like this restriction.

However, I doubt that removing the same attribute restriction will
improve the type system much. For example, if someone would
define a function 'f' with type

f :: a -> *a | Eq a

he would probably expect that the typechecker will accept:

g x = f (f x)

but because '*a' cannot be coerce to 'a' this is not allowed.

This might be more confusing for a programmer than a simple attribute
restriction.

The main problem with this restriction seems to occur in combination
with overloading. For example, it prevents class definitions like:

class T a where
	g :: a -> *a

Maybe this can be fixed by allowing only instances of types that
can be coerced (something similar is implemented for the Array class).

Kind regards,

John van Groningen


More information about the clean-list mailing list