[clean-list] a local function typing question in function composition

Philip Matthews philip_matthews at magma.ca
Thu Apr 12 18:09:36 MEST 2007


On 12-Apr-07, at 11:46 , Edsko de Vries wrote:

>
> No, not really. I am sorry that my use of "undefined" muddled the
> waters. Here is a similar example that doesn't use undefined, and does
> in fact return a value:
>
> module t
>
> f :: [a] -> [a]
> f x = y
>     where
>         y :: [a]
>         y = []
>
> Start = f [1,2,3]
>
> The empty list [] has type "[a]" (list of a) for every a (the empty  
> list is a
> list of integers, a list of bools, etc.). Now exactly the same  
> argument holds:
> y has type [a] for every a. The signature of f says that the result  
> must have
> the type type as the input, but since y has type [a] for every a,  
> that's not a
> problem. This program is type-correct and runs (and returns []).

This modified example helps a lot!  It makes it clear that practical  
expressions
can also have multiple types. Thank you for taking the time to  
explain this.


>
>> Never-the-less, from a practical prospective, I have learned the
>> following:
>>
>>     The type variables used in inner type declarations are ALWAYS
>>     different from the type variables in outer type declarations.
>>
>> If I remember this rule, I think I can understand and avoid typing
>> errors.
>
> Yes, if you find yourself using a type variable in an inner  
> function which you
> have also used in an outer function, chances are you are trying to  
> do something
> that won't work.


>
>> It would be helpful if the error message
>>
>>     Type error [t.icl,6,y]:type variable of type of lifted argument a
>>     appears in the specified type
>>
>> could be changed to be a little bit more comprehensible.
>
> I agree, but that's not up to me I'm afraid :)

Anyone from the Clean Compiler team want to chime in here about this  
suggestion?

In fact, how about changing Clean to disallow the use of a type  
variable name in an inner
type declaration if the same name appears in an outer type  
declaration? This would
prevent people from doing silly things.

- Philip



More information about the clean-list mailing list