[
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: | 2009-10-27 (18:25) |
From: | Jake Donham <jake@d...> |
Subject: | Re: [Caml-list] A strange typing error with polymorphic variants |
On Tue, Oct 27, 2009 at 3:28 AM, Marc de Falco <marc@de-falco.fr> wrote: > Hi, I've come across a very strange error, and I'm not sure if it is > a bug or a feature. > > The following code : > type 'a p = R of 'a t | E of float > and 'a t = { mutable p : 'a p; c : 'a } > let f = > let x = sqrt(2.0) in > fun () -> { c = `A; p = E 0.0 } > > generates the error : > The type of this expression, unit -> _[> `A ] t, > contains type variables that cannot be generalized > > but if I change the x definition to "let x = 2.0 in" then it works. > > Another solution is to add a dummy parameter "let f ?(dummy=())" this works > too. I think this is just the value restriction. The type of f is generalized only if the right hand side is a value (rather than an expression needing some computation); in your examples the one that fails is not a value, the others are. It looks like there is a relaxation to allow let bindings which are themselves values. Jake