On Tue, Oct 27, 2009 at 3:28 AM, Marc de Falco <m...@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

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to