From: rixed@happyleptic.org
To: caml-list@inria.fr
Subject: Re: [Caml-list] Bless me Father, for I have used Obj.magic
Date: Thu, 22 Dec 2011 23:19:59 +0100 [thread overview]
Message-ID: <20111222221958.GD8156@yeeloong.happyleptic.org> (raw)
In-Reply-To: <4EF3AA29.7000800@inria.fr>
-[ 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.
next prev parent reply other threads:[~2011-12-22 22:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-22 21:24 rixed
2011-12-22 22:07 ` Fabrice Le Fessant
2011-12-22 22:19 ` rixed [this message]
2011-12-22 23:29 ` Thierry Martinez
2011-12-23 12:04 ` rixed
2011-12-23 12:26 ` Fabrice Le Fessant
2011-12-30 11:41 ` Damien Doligez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111222221958.GD8156@yeeloong.happyleptic.org \
--to=rixed@happyleptic.org \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox