Version française
Home     About     Download     Resources     Contact us    
Browse thread
type of high order functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: bluestorm <bluestorm.dylc@g...>
Subject: Re: [Caml-list] type of high order functions
On Thu, Dec 16, 2010 at 9:32 AM, Alexander Bernauer <bernauer@inf.ethz.ch>wrote:

> If I don't specify a type, what's the inferred type of f? If I restrict
> f to the exact same type it should do no harm. At least, that is what I
> expected.


As Alain explained, the annotation you wrote is *not* the exact same type.
It's a different type where the scope of the 'a variable is wider, and
therefore less general. If you want to have the same semantics as the
inferred type (that is, a type variable quantified in the "let"
declaration-side but not use-side), you must use one of the
recently-introduced variable scoping constructs.

You're right that the scope rules for type inference variables are muddy at
best. This long underestimated issue has recently been under investigation,
as you can see with Alain's proposal (both syntaxes being only available
since the latest 3.12 version of OCaml), or the "Lexically scoped type
variables" [1] paper in the Haskell community (which describes and compare
the mutually incompatible behaviors of SML, Haskell and OCaml).

 [1]
http://research.microsoft.com/en-us/um/people/simonpj/papers/scoped-tyvars/