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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id 659B77F1C9 for ; Sun, 11 Nov 2012 10:26:15 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of didier.cassirame@gmail.com) identity=pra; client-ip=209.85.219.54; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="didier.cassirame@gmail.com"; x-sender="didier.cassirame@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of didier.cassirame@gmail.com designates 209.85.219.54 as permitted sender) identity=mailfrom; client-ip=209.85.219.54; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="didier.cassirame@gmail.com"; x-sender="didier.cassirame@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-oa0-f54.google.com) identity=helo; client-ip=209.85.219.54; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="didier.cassirame@gmail.com"; x-sender="postmaster@mail-oa0-f54.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsUBAOhtn1DRVds2m2dsb2JhbABEDoYLvTIIIwEBAQEBCAkLCRQngh4BAQQBIwQZARsdAQMBCwYFCw0qAgIhAQERAQUBHAYTh3cBAwkGnWeLY0+CeIN0ChknDVmIdQEFDIsghiCBEwOUJ4FVizKDMBYpg1Q+ X-IronPort-AV: E=Sophos;i="4.80,756,1344204000"; d="scan'208";a="162057530" Received: from mail-oa0-f54.google.com ([209.85.219.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 11 Nov 2012 10:26:14 +0100 Received: by mail-oa0-f54.google.com with SMTP id n9so9006251oag.27 for ; Sun, 11 Nov 2012 01:26:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=q3sFCdswB34oYG1pN7yuqEPEVSaVVb8kezVUIfLazA8=; b=qlkkZGCD4CeoHIdHN15h438+TQHUhHrCpzdi5KnKLlmqOCvBVE/gZ3D5A6AQtiCfn6 j9boGM/2SEWU4ZdfU56LXY2cgI5mAyPLOlKT8AbpGNdng/T1MaaZFbm1nLs5CllWeK+P Iv0djcEQTtRYlmKM7tPwvPbr73DxOBPn83w2WceW1An3PKvic865ZRWhCHesur1V9el/ uj3BLhzA+4y1sqLQXP7TE2Gm/EazrkBBKQfo0oD7FElMUdk6WlGn2KB7osO2FnJ8hhhk i4zOIt/OJFbC6VZzY1khyfd2LE5JaSB/vkN/cHGTJ7x5sP5BnFHwEyy+qYjHMTNfRy88 FV6w== Received: by 10.60.26.131 with SMTP id l3mr4785883oeg.118.1352625972706; Sun, 11 Nov 2012 01:26:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.60.137.198 with HTTP; Sun, 11 Nov 2012 01:25:52 -0800 (PST) In-Reply-To: <67E98D41-5721-4685-8AEF-806438A7E5B8@math.nagoya-u.ac.jp> References: <67E98D41-5721-4685-8AEF-806438A7E5B8@math.nagoya-u.ac.jp> From: Didier Cassirame Date: Sun, 11 Nov 2012 10:25:52 +0100 Message-ID: To: Jacques Garrigue Cc: "caml-list@inria.fr" Content-Type: multipart/alternative; boundary=e89a8ff1c5d69dfcb804ce34c67d Subject: Re: [Caml-list] parameterized classes, modules & polymorphic variants --e89a8ff1c5d69dfcb804ce34c67d Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable It's Great! Thanks! didier 2012/11/11 Jacques Garrigue > On 2012/11/09, at 23:25, Didier Cassirame > wrote: > > > Dear caml-list, > > > > I have been trying recently to combine classes, modules and variants > > in the following fashion: > > > > module A1 =3D struct > > > > class ['a] t =3D object > > constraint 'a =3D [>`a] > > method m : 'a -> string =3D function `a -> "a" | `a1 -> "a1" | _ = -> > "_" > > end > > > > end;; > > > > [=E2=80=A6] > > > > module type A =3D sig > > > > class ['a] t : object > > constraint 'a =3D [>`a] > > method m : 'a -> string > > end > > > > end;; > > > > type m =3D (module A);; > > > > let l: m list =3D [ (module A1); (module A2); (module A3)];; > > > > -------------------------------- > > > > Unfortunately the list typecheck fails. However, making a list of > > class instances from A1.t, A2.t, A3.t succeed, with the type: > > > > [> `a | `a1 | `a2 | `a3 ] ct list > > > > ct being defined as equal to A.t. > > > > I thought that perhaps I should parameterize the type m from the type > > parameter 'a of A.t to solve my problem, but I am not sure of the > > syntax, or if it's the problem. Does anyone have an idea? > > Actually the parameterization would not help here, since you want to put > them all in the same list. > The idea of using first-class modules is to be explicit about types, so > using an explicit type definition for a solves the problem. > > Jacques Garrigue > > module A1 =3D struct > type a =3D private [> `a | `a1] > > class t =3D object > method m : a -> string =3D function `a -> "a" | `a1 -> "a1" | _ -> "_" > end > end;; > > module A2 =3D struct > type a =3D private [> `a | `a2] > > class t =3D object > method m : a -> string =3D function `a -> "a" | `a2 -> "a2" | _ -> "_" > end > end;; > > module A3 =3D struct > type a =3D private [> `a | `a3] > > class t =3D object > method m : a -> string =3D function `a -> "a" | `a3 -> "a3" | _ -> "_" > end > end;; > > module type A =3D sig > type a =3D private [> `a] > class t : object > method m : a -> string > end > end;; > > type m =3D (module A);; > > let l: m list =3D [ (module A1); (module A2); (module A3)];; > > --e89a8ff1c5d69dfcb804ce34c67d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable It's Great! Thanks!

didier

2012/11/11 Jacques Garrigue <garrigue@math.nagoya-u.ac= .jp>
On 2012/11/09, at 23:25, D= idier Cassirame <didier.ca= ssirame@gmail.com> wrote:

> Dear caml-list,
>
> I have been trying recently to combine classes, modules and variants > in the following fashion:
>
> module A1 =3D struct
>
> =C2=A0class ['a] t =3D object
> =C2=A0 =C2=A0 =C2=A0 constraint 'a =3D [>`a]
> =C2=A0 =C2=A0 =C2=A0 method m : 'a -> string =3D function `a -&= gt; "a" | `a1 -> "a1" | _ -> "_"
> =C2=A0 end
>
> end;;
>
> [=E2=80=A6]
>
> module type A =3D sig
>
> =C2=A0class ['a] t : object
> =C2=A0 =C2=A0 =C2=A0 constraint 'a =3D [>`a]
> =C2=A0 =C2=A0 =C2=A0 method m : 'a -> string
> =C2=A0 end
>
> end;;
>
> type m =3D (module A);;
>
> let l: m list =3D [ (module A1); (module A2); (module A3)];;
>
> --------------------------------
>
> Unfortunately the list typecheck fails. However, making a list of
> class instances from A1.t, A2.t, A3.t succeed, with the type:
>
> [> `a | `a1 | `a2 | `a3 ] ct list
>
> ct being defined as equal to A.t.
>
> I thought that perhaps I should parameterize the type m from the type<= br> > parameter 'a of A.t to solve my problem, but I am not sure of the<= br> > syntax, or if it's the problem. Does anyone have an idea?

Actually the parameterization would not help here, since you want to = put them all in the same list.
The idea of using first-class modules is to be explicit about types, so usi= ng an explicit type definition for a solves the problem.

Jacques Garrigue

module A1 =3D struct
=C2=A0 type a =3D private [> `a | `a1]

=C2=A0 class t =3D object
=C2=A0 =C2=A0 method m : a -> string =3D function `a -= > "a" | `a1 -> "a1" | _ -> "_"
=C2=A0 end
end;;

module A2 =3D struct
=C2=A0 type a =3D private [> `a | `a2]

=C2=A0 class t =3D object
=C2=A0 =C2=A0 method m : a -> string =3D function `a -= > "a" | `a2 -> "a2" | _ -> "_"
=C2=A0 end
end;;

module A3 =3D struct
=C2=A0 type a =3D private [> `a | `a3]

=C2=A0 class t =3D object
=C2=A0 =C2=A0 method m : a -> string =3D function `a -= > "a" | `a3 -> "a3" | _ -> "_"
=C2=A0 end
end;;

module type A =3D sig
=C2=A0 type a =3D private [> `a]
=C2=A0 class t : object
=C2=A0 =C2=A0 method m : a -> st= ring
=C2=A0 end
end;;

type m =3D (module A);;

let l: m list =3D [ (module A1); (module A2); (module A3)];;


--e89a8ff1c5d69dfcb804ce34c67d--