[clean-list] Synonym type and Universal type

John van Groningen johnvg at cs.ru.nl
Fri May 11 10:42:05 MEST 2007


lethevert wrote:

>I have a question about synonym type and universal type.
>
>
>Section 5.3 in Clean Language Report version 2.1 says
>
>============================
>SynonymTypeDef = ::TypeLhs :== [UniversalQuantVariables]Type ;
>============================
>
>However I found some problem on using synonym type and universal type together.

This is an error in the manual. Universal quantors are not allowed
in type synonyms.

>The following program
>
>============================
>Start = f id 1 "a"
>
>id a = a
>
>::Id :== A.a: a -> a
>
>f :: Id Int String -> (Int, String)
>f g i s = (g i, g s)
>============================
>
>produces type unification errors.
>
>============================
>Compiling Main
>Type error [Main.icl,11,f]: near g : cannot unify types:
> v5 -> String
> Id
>Type error [Main.icl,5,Start]:"argument 1 of f" cannot unify types:
> Id
> v1 -> v1
>============================

The is caused by an error in the compiler, it should reject universal
quantors in type synonyms.

>But if we modify the first program as the following way
>
>============================
>::Id a :== a -> a
>
>f :: (A.a: Id a) Int String -> (Int, String)
>f g i s = (g i, g s)
>============================
>
>it doesn't produce any errors.
>
>
>Why this happens?

Universal quantors are allowed in function type specifications,
and only at the beginning of the type of a variable.

Kind regards,

John van Groningen


More information about the clean-list mailing list