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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 65B32BC57 for ; Mon, 30 Aug 2010 23:12:04 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqABALu7e0zRVdg0kGdsb2JhbACgYQgVAQEBAQkJDAcRAx+kNoknghOGJy6IVAEBAwWFMgSKCYhPggY X-IronPort-AV: E=Sophos;i="4.56,294,1280700000"; d="scan'208";a="56199339" Received: from mail-qw0-f52.google.com ([209.85.216.52]) by mail3-smtp-sop.national.inria.fr with ESMTP; 30 Aug 2010 23:12:02 +0200 Received: by qwi4 with SMTP id 4so23295qwi.39 for ; Mon, 30 Aug 2010 14:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:sender:received :in-reply-to:references:from:date:x-google-sender-auth:message-id :subject:to:cc:content-type; bh=dN0dJ6+I9XyZA/c7MZpAyFQjSpxIRbZbrzDEI/5qNvM=; b=gsz0ZqIKgfbiBK2HdwM6Ryrdm0C5HDPXymwUwvU1DqXdfeg8DS1g5i/UuH3ddQaMJO zv/Iwj8BbgRPSevbMKesirmyfUvA8D1ToAzEN7nlERe/nS/Za+LXAQgkY2mY3W481heM y9lTjOStxYCeKQ2SpeRp54rlKHwMmrihgEMNc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=hec49NQuG0FvJPsVMswhhqOI/XFcIFkkmXz6bkybH/lxJ30wsd74DLRVOL/d6i4NcI ZCIG2/w8jdy79owMOfu2LOaZmzFZZT6J5x1tlXhAdFyN1ndnuoTjOsKu0c9z8NZyp4hd q1MjVLZeB3hGa6i8cYpdY+DGKP4O4vyKLtjfs= Received: by 10.224.74.1 with SMTP id s1mr3372764qaj.26.1283202713281; Mon, 30 Aug 2010 14:11:53 -0700 (PDT) MIME-Version: 1.0 Sender: gabriel.scherer@gmail.com Received: by 10.229.185.206 with HTTP; Mon, 30 Aug 2010 14:11:33 -0700 (PDT) In-Reply-To: <231FBA54-C413-4696-AA70-216253EDF2DA@math.harvard.edu> References: <20100830204956.2D927BC5D@yquem.inria.fr> <231FBA54-C413-4696-AA70-216253EDF2DA@math.harvard.edu> From: bluestorm Date: Mon, 30 Aug 2010 23:11:33 +0200 X-Google-Sender-Auth: 8Mw7UKlT0muykQJtdCUK7Ncstng Message-ID: Subject: Re: [Caml-list] extending records with Obj.magic To: Nicolas Ojeda Bar Cc: caml-list@yquem.inria.fr Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; downcasting:01 wrote:01 extensible:01 caml-list:01 int:01 int:01 objects:02 seems:03 let:03 let:03 nicolas:08 correct:08 object:09 mess:09 aug:10 On Mon, Aug 30, 2010 at 11:04 PM, 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 } > You could use objects instead. ype t0 = < a : int > type t1 = < a : int; b : int > let x1 = object method a = 3 method b = 5 end let x0 = (x1 :> t0) (downcasting x0 -> x0' isn't correct)