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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id B48507F8BE for ; Sat, 3 May 2014 03:44:03 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.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=mail2-smtp-roc.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 (mail2-smtp-roc.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=mail2-smtp-roc.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 (mail2-smtp-roc.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=mail2-smtp-roc.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: AigBAHVJZFOFBoIFnGdsb2JhbABZFoM/gz+6Koc5gSQOAQEBAQEIFAk8giUBAQQBIwQZAwE1AQEDCwsYAgIYDgICVwYTiDkHDqUpd4NkAppchW0QAQaBKox1MweCLg8yNYEVigiPLIE8lHZeAQ X-IPAS-Result: AigBAHVJZFOFBoIFnGdsb2JhbABZFoM/gz+6Koc5gSQOAQEBAQEIFAk8giUBAQQBIwQZAwE1AQEDCwsYAgIYDgICVwYTiDkHDqUpd4NkAppchW0QAQaBKox1MweCLg8yNYEVigiPLIE8lHZeAQ X-IronPort-AV: E=Sophos;i="4.97,975,1389740400"; d="scan'208";a="71772341" Received: from rabbit.math.nagoya-u.ac.jp (HELO mailhost.math.nagoya-u.ac.jp) ([133.6.130.5]) by mail2-smtp-roc.national.inria.fr with ESMTP; 03 May 2014 03:43:52 +0200 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 612FC63EA; Sat, 3 May 2014 10:43:49 +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 DA9A84147; Sat, 3 May 2014 10:43:48 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=math.nagoya-u.ac.jp; h= content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; s=alpha; bh=kHh5d15NManfT4esdHQpjc1kkI4=; b=J6EMN+hhgLVrJoG0IzmF6q0nK4EP IFAQ0q+PlwDrw9Tdn1UBCNFtoP6lCEf5S+Z6/8ObJAd54fas3hPbP2mAmjTs/pVB r1msnf+Oj/pQIe839FhPlQ6fjyGDOL/ezQxk+aiPopdPpR/1RZOH2gGp1lKPdzUI QJQOhoLBW1MAHOA= DomainKey-Signature: a=rsa-sha1; h=Received:Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=RWwk2rOLmaiP5wtGDmMzjr1OohUW9kRxYaa1G4uSqDZo75xnAK/ZUiZfHOzHTnWy4JQLYVrG5lwixNUPDVI92vN3mH4Xe8AEHiyndyvvjlMFMmknynAstwz8lzFhZOH0E0awnEk+GPSLG67OZvOXNpVOO+N4eOD8w/hLTkqHbZ4=; c=nofws; d=math.nagoya-u.ac.jp; q=dns; 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 7AF454142; Sat, 3 May 2014 10:43:48 +0900 (JST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) From: Jacques Garrigue In-Reply-To: Date: Sat, 3 May 2014 10:43:46 +0900 Cc: OCaML List Mailing Content-Transfer-Encoding: quoted-printable Message-Id: References: <54FF3D28-6DAE-4C6A-B4B8-6D777570F3EB@math.nagoya-u.ac.jp> To: Berke Durak X-Mailer: Apple Mail (2.1874) Subject: Re: [Caml-list] Trying to define a functor combining polymorphic variants On 2014/05/03 00:50, Berke Durak wrote: >=20 > Thanks Leo and Jacques for the responses. >=20 > Jacques, if the PROD functor has to have a compatibility tag, doesn't > it mean that you can't reuse it to generate large products? i.e. how > would one write: A*B*C*D =3D PROD(A)(PROD(B)(PROD(C)(D))))? The compatibility annotation is on the functor. If the variant types in the modules you pass to the functor are concrete, they don=E2=80=99t need annotations. If you want to define a 4-ary functor that calls PROD, then its arguments will need annotations too, of course. For the details, you can see the internship report by Romain Bardou (in Fre= nch): Unions de variants polymorphes abstraits http://www.math.nagoya-u.ac.jp/~garrigue/papers/index.html Jacques Garrigue > On Fri, May 2, 2014 at 2:14 AM, Jacques Garrigue > wrote: >> On 2014/05/02 05:58, Berke Durak wrote: >>> So I naturally wanted to write a functor that does what the module AB d= oes: >>>=20 >>> module type S =3D sig >>> type message >>> val string_of_message : message -> string >>> end >>>=20 >>> module PROD(A : S)(B : S) =3D struct >>> type message =3D [ A.message | B.message ] >>> let string_of_message =3D function >>> | #A.t as msg -> A.string_of_message msg >>> | #B.t as msg -> B.string_of_message msg >>> end >>>=20 >>> But we (me + people on #ocaml: mrvn, drup, ggole, whitequark...) couldn= 't find a >>> way to specify, in the signature S, that message is a polymorphic varia= nt so >>> that [ A.message | B.message ] is legal. >>=20 >> There is a branch of the compiler which allows you to do that. >>=20 >> http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/varunion/ >>=20 >> Note that it contains only part of the directories. You can get the othe= rs >> from a pristine 3.10. >>=20 >> Using that version, you would write: >> module type S =3D sig >> type message =3D private [> ] >> =E2=80=A6 >> end >>=20 >> module PROD (A : S) (B : S with type message =3D private [> ] ~ A.messa= ge) =3D =E2=80=A6 >>=20 >> where the ~ is a compatibility annotation. >>=20 >> This was never merged because I couldn=E2=80=99t find a clean way to fix= some gap between >> theory and practice, but I may give it another try. >> Keigo Imai used it in his async_session code. >>=20 >> https://github.com/keigoi/async_session/blob/master/varunion_session.ml >>=20 >> Jacques Garrigue