From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id D8B467EEB4 for ; Sun, 3 Feb 2013 00:18:47 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of cedilla@gmail.com) identity=pra; client-ip=209.85.223.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="cedilla@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of cedilla@gmail.com designates 209.85.223.175 as permitted sender) identity=mailfrom; client-ip=209.85.223.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="cedilla@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ie0-f175.google.com) identity=helo; client-ip=209.85.223.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="cedilla@gmail.com"; x-sender="postmaster@mail-ie0-f175.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsABAO+dDVHRVd+vm2dsb2JhbABFhkiBPbcmCBYOAQEBAQEICQsJFCeCSQQZARseAxIJBzcCJAERAQUBPYd2AQMPoG+CcItlT4J7g3gKGScNWYh3AQUMjh2CFoETA4hmjTmOcBYphD8 X-IPAS-Result: AsABAO+dDVHRVd+vm2dsb2JhbABFhkiBPbcmCBYOAQEBAQEICQsJFCeCSQQZARseAxIJBzcCJAERAQUBPYd2AQMPoG+CcItlT4J7g3gKGScNWYh3AQUMjh2CFoETA4hmjTmOcBYphD8 X-IronPort-AV: E=Sophos;i="4.84,591,1355094000"; d="scan'208";a="871740" Received: from mail-ie0-f175.google.com ([209.85.223.175]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 03 Feb 2013 00:15:23 +0100 Received: by mail-ie0-f175.google.com with SMTP id c12so4476616ieb.6 for ; Sat, 02 Feb 2013 15:18:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=2n6PJZvKXrkaEVDdHHSynAxpo67TdEH5JW6P0ucuruo=; b=wccFxA2qvRaemuQi2/OXCV3lFRJEiJgayg7MdvwgHCEGF8DJaVDNkzldrOX8yYd3Fn p148zTDYkwbFHhskF694u5x9FhXRvTz6ZV0cfZivSYhbINOeaepOduBsKUU4waKGQO5q u0n1+SgE85xBLa4Vpow7ShvkLtrXhLTacOye70eOQf/0jDGga5YvT83MdHqmk9xmnRmU C7Bki3UnYCVN70WVmphxKZYHyPOuRQGFwHG2YJTTBlS1F+UrQldVboxpuGedIRZ59+iF knvNRp1l0ABv16vsuWvKpXUuEVbfpjNm/lUxkY0tIqM45nI0hcLFktTVhySIIcqmJbKF AK4w== MIME-Version: 1.0 X-Received: by 10.50.173.66 with SMTP id bi2mr1942771igc.77.1359847125539; Sat, 02 Feb 2013 15:18:45 -0800 (PST) Received: by 10.64.6.1 with HTTP; Sat, 2 Feb 2013 15:18:45 -0800 (PST) Date: Sat, 2 Feb 2013 15:18:45 -0800 Message-ID: From: Reed Wilson To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=e89a8f503770dddcb104d4c61424 X-Validation-by: cedilla@gmail.com Subject: [Caml-list] Objects and polymorphic variants --e89a8f503770dddcb104d4c61424 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Greetings list, I've been trying to make object methods that return polymorphic variants, but it looks a bit stricter than I'm used to. For example, take the following methods: method private method_12 =3D function | 1 -> `One | _ -> `Two method method_123 =3D function | 3 -> `Three | x -> self#method_12 x method method_124 =3D function | 4 -> `Four | x -> self#method_12 x This returns the type: method private method_12 : int -> ([ > `Four | `One | `Three | `Two ] as 'a) method method_123 : int -> 'a method method_124 : int -> 'a and complains that method_123 uses 'a, which is undefined. That's fair enough, since it's an open type in a non-private method. However, if I give method_123 or method_124 a closed type signature it will give the same exact type to the other two methods. What I really want is a signature like this: method private method_12 : int -> [ > `One | `Two ] method method_123 : int -> [ `One | `Two | `Three ] method method_124 : int -> [ `One | `Two | `Four ] If I replace method_12 with a function outside the class it works fine, but for whatever reason method_12 really wants to be the exact same type as method_123 and method_124. Is there any way around this typing requirement for methods? Thanks for any help, Reed Wilson PS. I'd rather avoid doing any verbose "post-processing" of the method_12 result, like this: method_123 =3D function | 3 -> `Three | x -> (match self#method_12 with `One -> `One | `Two -> `Two) --=20 =C3=A7 --e89a8f503770dddcb104d4c61424 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Greetings list,
=C2=A0
I've been trying to mak= e object=C2=A0methods that return polymorphic variants, but it looks a bit = stricter than I'm used to.
For example, take the following me= thods:
=C2=A0
method private method_12 =3D function
| 1 -= > `One
| _ -> `Two
=C2=A0
method method= _123 =3D function
| 3 -> `Three
| x -> self#metho= d_12 x
=C2=A0
method method_124 =3D function
| 4 -> `F= our
| x -> self#method_12 x
=C2=A0
This re= turns the type:
method private method_12 : int -> ([ > `Fou= r |=C2=A0`One | `Three | `Two ] as 'a)
method method_123 : int -> 'a
method method_124 : int= -> 'a
=C2=A0
and complains that method_123 uses= =C2=A0'a, which is=C2=A0undefined. That's fair enough, since it'= ;s an open type in a non-private method.
However, if I give method_123 or method_124 a closed type signature it= will give the same exact=C2=A0type to the other two methods.
=C2= =A0
What I really want is a signature like this:
method= private method_12 : int -> [ > `One | `Two ]
method method_123 : int -> [ `One | `Two | `Three ]
metho= d method_124 : int -> [ `One | `Two | `Four ]
=C2=A0
If I replace method_12 with=C2=A0a function outside the class it works fin= e, but for whatever reason method_12 really wants to be the exact same type= as method_123 and method_124.
=C2=A0
Is there any way around this typing requirement for m= ethods?
=C2=A0
=C2=A0
Thanks for any help,
Reed Wilson
=C2=A0
=C2=A0
PS. I'd= rather avoid doing any verbose=C2=A0"post-processing" of the met= hod_12 result, like this:
method_123 =3D function
| 3 -> `Three
| x -> (match= self#method_12 with `One -> `One | `Two -> `Two)
=C2=A0

--
=C3=A7
--e89a8f503770dddcb104d4c61424--