Carlos Aya wrote:
Does anyone know why the following type signature is invalid?

second :: *a .a -> *a
second x y = x

I am getting this message
Error [matrices.icl,12,second]: a inconsistently attributed (4)

The same uniqueness attribute must be used for all occurrences of
a type variable in a function type.

I came across this trying to type a more complex function with arrays, but it boils down to signature above.

Why the uniqueness attribute has to be the same for two independent parameters that just happen to have the same type?

A type '*a' cannot be coerced to 'a', because 'a' could be a partial
application with a unique argument. It this were allowed the unique
argument could be used more than once. Because the opposite coercion
(from 'a' to '*a') is also not possible, the compiler requires that
all occurences of a type variable have the same uniqueness attribute
(as mentioned above).

This is explained in section "Higher-Order Uniqueness Types" (page 18) of:

Barendsen, Erik and Smetsers, Sjaak. Uniqueness typing for functional languages with graph rewriting semantics, In Mathematical Structures in Computer Science 6, pp. 579-612. (abstract, pdf version)

http://www.st.cs.ru.nl/papers/1996/bare96-uniclosed.pdf

Kind regards,

John van Groningen
_______________________________________________
clean-list mailing list
[email protected]
http://mailman.science.ru.nl/mailman/listinfo/clean-list

Reply via email to