From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id pBMM7kOC009169 for ; Thu, 22 Dec 2011 23:07:46 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AioBAKGp807RVdS2kWdsb2JhbABDhQ+nGQgiAQEBAQkLCwcUBCGBcgEBAQMBEgIPBBkBNwIDAQsBBQUYCRYLAgIJAwIBAgEiAQUBHBMGAgEBHodYApo4CosdgzOEaokwAgULiGqCBIEWBI4lgReFRYVPgTSGeD2BTYIu X-IronPort-AV: E=Sophos;i="4.71,395,1320620400"; d="vcf'?scan'208";a="124376932" Received: from mail-wi0-f182.google.com ([209.85.212.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 22 Dec 2011 23:07:41 +0100 Received: by wibhr1 with SMTP id hr1so5146814wib.27 for ; Thu, 22 Dec 2011 14:07:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:x-enigmail-version:content-type; bh=DZS9tHt3+TbUwMAOmoHjyyXpEzfcJiWxYqr4LTG6anI=; b=xNW0ctCVhUtgMX8KJBQIulG9LnvfNcM3ro3iOQZ0JpxOZLQob11MYBZGxOoS+tW8ln osf5IjUw5Bi9WRYKV+aJiT7DJ88ZGVhtePI75rLG0W/gvj2wINshT8T8Kp2+1S88Why+ VZlxkEhyHKPBphOWRFdXY6S4OpvUgpMbvocrM= Received: by 10.180.77.42 with SMTP id p10mr27311481wiw.5.1324591660799; Thu, 22 Dec 2011 14:07:40 -0800 (PST) Received: from [192.168.0.29] (gov91-4-83-152-214-51.fbx.proxad.net. [83.152.214.51]) by mx.google.com with ESMTPS id eg7sm26023652wib.8.2011.12.22.14.07.38 (version=SSLv3 cipher=OTHER); Thu, 22 Dec 2011 14:07:39 -0800 (PST) Sender: Fabrice Le Fessant Message-ID: <4EF3AA29.7000800@inria.fr> Date: Thu, 22 Dec 2011 23:07:37 +0100 From: Fabrice Le Fessant User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Lightning/1.0b2 Thunderbird/3.1.15 MIME-Version: 1.0 To: caml-list@inria.fr References: <20111222212429.GA8156@yeeloong.happyleptic.org> In-Reply-To: <20111222212429.GA8156@yeeloong.happyleptic.org> X-Enigmail-Version: 1.1.2 Content-Type: multipart/mixed; boundary="------------010907060705050106080400" X-Validation-by: fabrice.le_fessant@inria.fr Subject: Re: [Caml-list] Bless me Father, for I have used Obj.magic This is a multi-part message in MIME format. --------------010907060705050106080400 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 12/22/2011 10:24 PM, rixed@happyleptic.org 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 --------------010907060705050106080400 Content-Type: text/x-vcard; charset=utf-8; name="fabrice_le_fessant.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fabrice_le_fessant.vcf" begin:vcard fn:Fabrice LE FESSANT n:LE FESSANT;Fabrice org:INRIA Saclay -- Ile-de-France;P2P & OCaml adr;quoted-printable:;;Parc Orsay Universit=C3=A9 ;Orsay CEDEX;;91893;France email;internet:fabrice.le_fessant@inria.fr title;quoted-printable:Charg=C3=A9 de Recherche tel;work:+33 1 74 85 42 14 tel;fax:+33 1 74 85 42 49 url:http://fabrice.lefessant.net/ version:2.1 end:vcard --------------010907060705050106080400--