From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA04267; Tue, 9 Sep 2003 16:20:52 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA32678 for ; Tue, 9 Sep 2003 16:20:51 +0200 (MET DST) Received: from mail1.telekom.de (mail1.telekom.de [62.225.183.202]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h89EKoT08118 for ; Tue, 9 Sep 2003 16:20:51 +0200 (MET DST) Received: from g9jbr.mgb01.telekom.de by G8SBV.dmz.telekom.de with ESMTP for caml-list@inria.fr; Tue, 9 Sep 2003 16:13:32 +0200 Received: by G9JBR.mgb01.telekom.de with Internet Mail Service (5.5.2653.19) id ; Tue, 9 Sep 2003 16:13:31 +0200 Message-Id: From: "Beck01, Wolfgang" To: caml-list@inria.fr Subject: RE: [Caml-list] strange behaviour with variants and "cannot be g eneralized" Date: Tue, 9 Sep 2003 16:13:29 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Loop: caml-list@inria.fr X-Spam: no; 0.00; t-systems:01 caml-list:01 t-systems:01 compiles:01 3.07:01 implemented:01 real-world:01 arrays:01 arrays:01 ocaml:01 mutable:01 variants:01 variants:01 workaround:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > > From: "Beck01, Wolfgang" > > > 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