Browse thread
Labels and polymorphism
[
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: | 2007-03-08 (19:14) |
From: | Eric Cooper <ecc@c...> |
Subject: | Re: [Caml-list] Labels and polymorphism |
On Thu, Mar 08, 2007 at 10:31:46AM -0800, Nathaniel Gray wrote: > # let f ~x = x;; > val f : x:'a -> 'a = <fun> > # f ~x:1;; > - : int = 1 > # f 1;; > - : x:(int -> 'a) -> 'a = <fun> > > Can somebody make sense of this for me? Is there a paper somewhere on > labels in ocaml that I should read? Section 6.7.1 of the manual, subsection "Function application", says: As a special case, if the function has a known arity, all the arguments are unlabeled, and their number matches the number of non-optional parameters, then labels are ignored and non-optional parameters are matched in their definition order. The problem is that if the result type of a function f is 'a, then it's not of known arity -- an application of f could produce a function, which could then be applied to more arguments. For example: # let id x = x;; val id : 'a -> 'a = <fun> # id id id id 17;; - : int = 17 In your example, if you constrain the type of f, it works as expected: # (f : x:int->int) 1;; - : int = 1 -- Eric Cooper e c c @ c m u . e d u