Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] strange behaviour with variants and "cannot be generalized"
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] strange behaviour with variants and "cannot be generalized"
From: "Beck01, Wolfgang" <BeckW@t-systems.com>

> v1.ml ----------------------------
> 
> open Vtop
> 
> type t = {
>     v1_x : int array;
> }
> 
> let init = `V1 { v1_x = [| 0 |] }
> 
> compilation fails with "The type of this expression _[> `V1 of t ] Vtop.t,
> contains type variables that cannot be generalized"
> 
> However, if I change the type of v1_x to a string or some large struct,
> it compiles without warning and works. The error seems only to occur
> with arrays. I am using version 3.06. 
> 
> Is there an explanation for this behaviour?

Sure: [| 0 |] creates a mutable data structure, and as such is
considered as a side-effecting expression. As a result the type of
init cannot be generalized.

OCaml 3.07 is more clever about that, and the above program would be
accepted with no problem.

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners