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 986847F8BE for ; Fri, 2 May 2014 08:14:42 +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: ApwBAHs3Y1OFBoIFnGdsb2JhbABag1WDPro1hz6BKQ4BAQEBAQgUCTyCJQEBBSMEGQMBNQEBDgsYAgImAgJXBohTDqUSd4NkApomhW4QAQaBKox1MweCLg8yNYEVigiPK4E8lHUu X-IPAS-Result: ApwBAHs3Y1OFBoIFnGdsb2JhbABag1WDPro1hz6BKQ4BAQEBAQgUCTyCJQEBBSMEGQMBNQEBDgsYAgImAgJXBohTDqUSd4NkApomhW4QAQaBKox1MweCLg8yNYEVigiPK4E8lHUu X-IronPort-AV: E=Sophos;i="4.97,971,1389740400"; d="scan'208";a="71583413" 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; 02 May 2014 08:14:23 +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 0021063FD; Fri, 2 May 2014 15:14:20 +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 849CA414D; Fri, 2 May 2014 15:14:20 +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=ygZ6ZSYAIXqLk78Btt6Fx+zkjdo=; b=VnlacEshAzj5D9GF5QXN366KEdRi x6Tq3/Kcwl/JOOKrzi94HD8XHbjtpCaplLjZG+WKuVZDFTwgMxHTPuWkLzxF/d4C y0vutxTfqXnIfXkS7Hym6/HaOSKLWr4zGorSqGhgsAIDxdV/iFj8CXXrUF647mOT kCIoKLW5tgyx6tg= 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=f54vnzBjjlO3RpZLC5k1XfKvISNLrv8pKY1xpeX6FcmVS//8u/Wumf3nQy2iCVOgID0JDe7A2doOdb4yjyYHd95nTMNKotPdWMpn/imZ9gMpgxFwsMBcITNbcZSaLTU1zUV6t0d+y2WKVydAXQs967riRvLbBcf/FSPnapEu0C8=; c=nofws; d=math.nagoya-u.ac.jp; q=dns; s=alpha Received: from garrigue-mini.math.nagoya-u.ac.jp (garrigue-mini.math.nagoya-u.ac.jp [172.16.30.37]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 7CBB84142; Fri, 2 May 2014 15:14:20 +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: Fri, 2 May 2014 15:14:20 +0900 Cc: Mailing List OCaml Content-Transfer-Encoding: quoted-printable Message-Id: <54FF3D28-6DAE-4C6A-B4B8-6D777570F3EB@math.nagoya-u.ac.jp> References: To: Berke Durak X-Mailer: Apple Mail (2.1874) Subject: Re: [Caml-list] Trying to define a functor combining polymorphic variants On 2014/05/02 05:58, Berke Durak wrote: > So I naturally wanted to write a functor that does what the module AB doe= s: >=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 variant= so > that [ A.message | B.message ] is legal. There is a branch of the compiler which allows you to do that. http://caml.inria.fr/cgi-bin/viewvc.cgi/ocaml/branches/varunion/ Note that it contains only part of the directories. You can get the others from a pristine 3.10. Using that version, you would write: module type S =3D sig type message =3D private [> ] =E2=80=A6 end module PROD (A : S) (B : S with type message =3D private [> ] ~ A.message= ) =3D =E2=80=A6 where the ~ is a compatibility annotation. This was never merged because I couldn=E2=80=99t find a clean way to fix so= me gap between theory and practice, but I may give it another try. Keigo Imai used it in his async_session code. https://github.com/keigoi/async_session/blob/master/varunion_session.ml Jacques Garrigue=