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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Beck01, Wolfgang <BeckW@t...>
Subject: RE: [Caml-list] strange behaviour with variants and "cannot be g eneralized"
> 
> 
> From: "Beck01, Wolfgang" <BeckW@t-systems.com>
> 
> > v1.ml ----------------------------
> > 
> > open Vtop
> > 
> > type t = {
> >     v1_x : int array;
> > }
> > 
> > let init = `V1 { v1_x = [| 0 |] }
> 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.

Funnily, I just found a workaround:
v1.ml ----------------------------
open Vtop

type r_t = {
    r_a : int array;
}

type t = {
    v1_x : r_a;
}
let r_init = { r_a = Array.make 100 0 }
let init = `V1 { v1_x = r_init }
----------------------------------
compiles. However, "let init = `V1 { v1_x = { r_a = Array.make 100 0 }} "
does not. 

> 
> OCaml 3.07 is more clever about that, and the above program would be
> accepted with no problem.
> 
Good to hear. I have introduced variants im my major project after playing
around with toy programs like the one above. But I did not check if
arrays would work. After a week of rearranging my code, I successfully
implemented my first real-world variant (without an array). Then, I
started a second one yesterday and was quite upset when I found that
it did not compile (it took me some time to find that arrays were causing
the trouble). 


Regards,

Wolfgang Beck

-------------------
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