On 12/22/2011 10:24 PM, [email protected] wrote:
> I have these types:
> 
> type t = { operation : t1 -> t2 ;
>            some_fields : of_some_types }
> type t_priv = { t : t ;
>                 some_other_fields : of_some_other_types }

> Should I fear some backfire?

You might one day forget this [Obj.magic], and access the field [t] that
has not yet been initialized, and get a segfault.

My advise would be to first create a dummy [t] record:

let dummy_t = { operation = (fun _ -> failwith "t not initialized");
                some_fields = ... some dummy initializer .. }

and use it as the initial value for uninitialized values.

let t_priv = { t = dummy_t; ... }
in
let t = make_operations t_priv in
t_priv.t <- t

The good thing is that, since it is uniq in your program, you can test
if t_priv was initialized easily:

if t_priv.t == dummy_t then failwith "t_priv not yet constructed !"

--Fabrice

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

<<attachment: fabrice_le_fessant.vcf>>

Reply via email to