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 5829C7F1C9 for ; Sun, 11 Nov 2012 09:21:18 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of garrigue@math.nagoya-u.ac.jp) identity=pra; client-ip=133.6.130.5; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="garrigue@math.nagoya-u.ac.jp"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of garrigue@math.nagoya-u.ac.jp) identity=mailfrom; client-ip=133.6.130.5; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="garrigue@math.nagoya-u.ac.jp"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mailhost.math.nagoya-u.ac.jp) identity=helo; client-ip=133.6.130.5; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="postmaster@mailhost.math.nagoya-u.ac.jp"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap4EABJfn1CFBoIF/2dsb2JhbABEhhm+QoIeAQEEASEBBRwBNQIDCwsZAwsNDQMCITYGE4d4AwkFqGVrAYNRAYQ4DUyJAQeBH4oNhh01YYhbi0+BVYsyhRGCfg X-IronPort-AV: E=Sophos;i="4.80,756,1344204000"; d="scan'208";a="162054801" Received: from rabbit.math.nagoya-u.ac.jp (HELO mailhost.math.nagoya-u.ac.jp) ([133.6.130.5]) by mail4-smtp-sop.national.inria.fr with ESMTP; 11 Nov 2012 09:21:15 +0100 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id B2B486358; Sun, 11 Nov 2012 17:21:12 +0900 (JST) Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 865F340E1; Sun, 11 Nov 2012 17:21:12 +0900 (JST) DomainKey-Signature: h=Received:Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=; c=nofws; d=math.nagoya-u.ac.jp; q=; s=alpha Received: from tet.garrigue.jp (58x158x128x157.ap58.ftth.ucom.ne.jp [58.158.128.157]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTPSA id 58B3524D1; Sun, 11 Nov 2012 17:21:12 +0900 (JST) Content-Type: text/plain; charset=iso-2022-jp Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) From: Jacques Garrigue In-Reply-To: Date: Sun, 11 Nov 2012 17:21:10 +0900 Cc: "caml-list@inria.fr" Content-Transfer-Encoding: quoted-printable Message-Id: <67E98D41-5721-4685-8AEF-806438A7E5B8@math.nagoya-u.ac.jp> References: To: Didier Cassirame X-Mailer: Apple Mail (2.1499) Subject: Re: [Caml-list] parameterized classes, modules & polymorphic variants On 2012/11/09, at 23:25, Didier Cassirame wrot= e: > Dear caml-list, >=20 > I have been trying recently to combine classes, modules and variants > in the following fashion: >=20 > module A1 =3D struct >=20 > class ['a] t =3D object > constraint 'a =3D [>`a] > method m : 'a -> string =3D function `a -> "a" | `a1 -> "a1" | _ ->= "_" > end >=20 > end;; >=20 > [=1B$B!D=1B(B] >=20 > module type A =3D sig >=20 > class ['a] t : object > constraint 'a =3D [>`a] > method m : 'a -> string > end >=20 > end;; >=20 > type m =3D (module A);; >=20 > let l: m list =3D [ (module A1); (module A2); (module A3)];; >=20 > -------------------------------- >=20 > Unfortunately the list typecheck fails. However, making a list of > class instances from A1.t, A2.t, A3.t succeed, with the type: >=20 > [> `a | `a1 | `a2 | `a3 ] ct list >=20 > ct being defined as equal to A.t. >=20 > 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 th= em 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 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)];;