From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 94FEABC57 for ; Mon, 30 Aug 2010 23:43:35 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ar0AAHbDe0xCbwQZkWdsb2JhbACgaRUBAQEBCQsKBxEEHr8lBYU3hD+QIw X-IronPort-AV: E=Sophos;i="4.56,294,1280700000"; d="scan'208";a="66328875" Received: from out1.smtp.messagingengine.com ([66.111.4.25]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 30 Aug 2010 23:43:34 +0200 Received: from compute3.internal (compute3.internal [10.202.2.43]) by gateway1.messagingengine.com (Postfix) with ESMTP id 57689164; Mon, 30 Aug 2010 17:43:33 -0400 (EDT) Received: from frontend2.messagingengine.com ([10.202.2.161]) by compute3.internal (MEProxy); Mon, 30 Aug 2010 17:43:33 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=message-id:date:from:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; s=smtpout; bh=BhS31/JEn57iT2iHzR9bqFkIU1o=; b=ODBEyiZQN9KhPRJ98T33RNI/ERuqkU0da9SswdMCpX5+++oTmYdp9/DC6uW5ylPFZNWhuykqH18DGFYg1OB1ZdeJH9p0OBksQBZgNItzelTI7l4FcZ48gJ8AWw3dsLSVQWSShH9rNoJHXeq+D4JLAf6NMBAz67HtDGTJRXqSf9o= X-Sasl-enc: TCPUB1Tvq8x+FnCW2VSEldJpgf6kSQrIX2Nux0Izhn8L 1283204613 Received: from [192.168.1.61] (64-71-1-165.static.wiline.com [64.71.1.165]) by mail.messagingengine.com (Postfix) with ESMTPSA id EA24E5E2663; Mon, 30 Aug 2010 17:43:32 -0400 (EDT) Message-ID: <4C7C2603.9080909@ens-lyon.org> Date: Mon, 30 Aug 2010 14:43:31 -0700 From: Martin Jambon User-Agent: Thunderbird 2.0.0.22 (X11/20090908) MIME-Version: 1.0 To: Nicolas Ojeda Bar Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] extending records with Obj.magic References: <20100830204956.2D927BC5D@yquem.inria.fr> <231FBA54-C413-4696-AA70-216253EDF2DA@math.harvard.edu> In-Reply-To: <231FBA54-C413-4696-AA70-216253EDF2DA@math.harvard.edu> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ens-lyon:01 val:01 val:01 wrote:01 extensible:01 caml-list:01 int:01 int:01 jambon:01 jambon:01 seems:03 float:03 float:03 let:03 let:03 Nicolas Ojeda Bar wrote: > Hello, > > I need extensible records, and the code below seems to > work. Are there any pitfall that I should be aware of? > Could this mess up the GC? > > # type t0 = { a : int }; > # type t1 = { a2 : int; b : int }; > # value x1 = { a2 = 3; b = 5 }; > # value x0 : t0 = Obj.magic x1; > value x0 = { a = 3 } > # value x0' : t1 = Obj.magic x0; > value x0' = { a2 = 3; b = 5 } > > (supposedly t1 is an extension of t0). The types are > being generated by a program, so I am not worried about > actually having to _write_ this myself. # type t0 = { a : float };; type t0 = { a : float; } # type t1 = { a2 : float; b : int };; type t1 = { a2 : float; b : int; } # let x1 = { a2 = 3.; b = 5 };; val x1 : t1 = {a2 = 3.; b = 5} # let x0 : t0 = Obj.magic x1;; val x0 : t0 = {a = 3.} And now the magic: # x0.a;; - : float = 6.94364726476075e-310 Martin -- http://mjambon.com/