-[ Thu, Dec 22, 2011 at 11:07:37PM +0100, Fabrice Le Fessant ]----
> You might one day forget this [Obj.magic], and access the field [t] that
> has not yet been initialized, and get a segfault.
As the only place where this 0 value exists is in the constructor and
it can easily be shown that the function never returns a semi-initialized
t, then this looks quite unprobable here. But I welcome the warning
nonetheless :-)
> 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 .. }
Yes, this was my initial intention as well.
Unfortunately, my actual types are much more complex than what's shown
in the example; especially a value of type t2 is quite hairy to construct
and there are lots of operations having lots of complex output types
(records of records of functions of records...) That's why I had this
TODO note in the margin commanding to "build a dummy t to get rid of the
option type" for so long, until I had this terrible idea of using
Obj.magic.
--
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