From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p2UEFW1w019977 for ; Wed, 30 Mar 2011 16:15:32 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvkCAIc6k03RVdg0kGdsb2JhbACYH4Y5hnEIFAEBAQEJCQ0HFAQhiHmZM4pVgiKFLi+IXAEBAwWFZQSBe4sLiQ06 X-IronPort-AV: E=Sophos;i="4.63,269,1299452400"; d="scan'208";a="104059310" Received: from mail-qw0-f52.google.com ([209.85.216.52]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 30 Mar 2011 16:15:26 +0200 Received: by qwb8 with SMTP id 8so1242780qwb.39 for ; Wed, 30 Mar 2011 07:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=sa3zThdsZsxLg431T5whAr/5FkB0i7r5wjC5KFb4mPc=; b=TMFwkoUUlo1nJHWz/Sckm/R6F5UW9M0IcUN2hSm8N9Jz9hJu9q9GrWj/ViW7mnIqXf H81PvfBiBcChDL4KuROOQoBQvi4/5brdA4rTtyqTitIhqLICCvsypvGwO8vucd5D7c8s 3UpKw+uO5w1PMIkgDgo2JKqKJ1rhRHtL/59wM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=WnY1YIsaLk5y++wqJVMjTpj78GWl/DDD1ub4DK1F0c5Sy5YwVYhvVzpz5kND9xKTTj CgAX5K5HKOSWYbqIRjA8aGHi6fSV2B+Z2zhoUrrnWSWpdAXrnoyJJpJpSZaLbjcQDlgE waiYZ3im21tFpRsBBQlakVERazG9DtouKgg0Q= Received: by 10.229.1.234 with SMTP id 42mr1071960qcg.91.1301494525219; Wed, 30 Mar 2011 07:15:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.235.146 with HTTP; Wed, 30 Mar 2011 07:15:05 -0700 (PDT) In-Reply-To: <4D932456.4000803@wp.pl> References: <74205EDF-69A3-479A-9214-52D2AB849558@gmail.com> <13A708B2-732E-4D51-A740-BCFDC4E0212F@gmail.com> <4D932456.4000803@wp.pl> From: Gabriel Scherer Date: Wed, 30 Mar 2011 16:15:05 +0200 Message-ID: To: Dawid Toton Cc: caml-list@yquem.inria.fr Content-Type: multipart/alternative; boundary=0014853a0216da606b049fb3cea3 Subject: Re: [Caml-list] Re: function that works on different record types, assuming they have a given field --0014853a0216da606b049fb3cea3 Content-Type: text/plain; charset=ISO-8859-1 Why not pass the value of the "x" field directly to the function, instead of trying to receive a would-be { x : 'a; .... } parameter ? If you would have liked the field to be mutable, make it a reference. On Wed, Mar 30, 2011 at 2:38 PM, Dawid Toton wrote: > On 03/28/2011 08:35 PM, Joel Reymont wrote: > > On Mar 28, 2011, at 7:34 PM, David Rajchenbach-Teller wrote: > > > >> you can obtain the same behavior by using objects instead of records: > > Yes, that used to work very well... until I was forced to switch to > records :-). > > > When I had this problem I used one common record type: > > type ('foo, 'bar') common = > {foo : 'foo > ;bar : 'bar > ;x : int > } > > type with_bar = (unit, string) common > type with_foo = (double, unit) common > > However, I can see that with more different independent types this is > going to be quite ugly. > > Dawid > > -- > 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 > --0014853a0216da606b049fb3cea3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Why not pass the value of the "x" field directly to the function,= instead of trying to receive a would-be { x : 'a; .... } parameter ?If you would have liked the field to be mutable, make it a reference.

On Wed, Mar 30, 2011 at 2:38 PM, Dawid Toton= <d0@wp.pl> = wrote:
On 03/28/2011 08:35 PM, Joel Reymont wrote:
> On Mar 28, 2011, at 7:34 PM, David Rajchenbach-Teller wrote:
>
>> you can obtain the same behavior by using objects instead of recor= ds:
> Yes, that used to work very well... until I was forced to switch to re= cords :-).
>
When I had this problem I used one common record type:

type ('foo, 'bar') common =3D
=A0{foo : 'foo
=A0;bar : 'bar
=A0;x : int
=A0}

type with_bar =3D (unit, string) common
type with_foo =3D (double, unit) common

However, I can see that with more different independent types this is
going to be quite ugly.

Dawid

--
Caml-list mailing list. =A0Subscription 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
--0014853a0216da606b049fb3cea3--