Labels and polymorphism

Nathaniel Gray
 Eric Cooper
 Roland Zumkeller
 skaller
[
Home
]
[ Index:
by date

by threads
]
[ Message by date: previous  next ] [ Message in thread: previous  next ] [ Thread: previous  next ]
[ Message by date: previous  next ] [ Message in thread: previous  next ] [ Thread: previous  next ]
Date:  20070308 (19:41) 
From:  Roland Zumkeller <roland.zumkeller@g...> 
Subject:  Re: [Camllist] Labels and polymorphism 
On 08/03/07, Nathaniel Gray <n8gray@gmail.com> wrote: > # let f ~x = x;; > val f : x:'a > 'a = <fun> > # f ~x:1;; >  : int = 1 > # f 1;; >  : x:(int > 'a) > 'a = <fun> The "1" is assumed to be an argument to "f ~x:a" (where "a" is yet to be given). Therefore "f ~x:a" must be of type "int > ...". Now "f ~x:a" is of the same type as (and here actually reduces to) "a". Hence this type for the xlabeled argument. Perhaps looking at this might help, too: # f 1 1 1;;  : x:(int > int > int > 'a) > 'a = <fun> Now you ask, why are things as they are? Why can't OCaml guess that the "1" was meant for the label "x"? Probably it could, but with such a typing rule we would have to write "(fun ~x:a > f ~x:a 1)" for what is currently "f 1" (partial application would be essentially lost here). In contrast, becoming able to write "f x" instead of "f ~x:1" seems not enough of a gain to compensate this. Best, Roland  http://www.lix.polytechnique.fr/~zumkeller/