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 62BF57F8BF for ; Fri, 2 May 2014 17:50:24 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of berke.durak@gmail.com) identity=pra; client-ip=209.85.128.179; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="berke.durak@gmail.com"; x-sender="berke.durak@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of berke.durak@gmail.com designates 209.85.128.179 as permitted sender) identity=mailfrom; client-ip=209.85.128.179; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="berke.durak@gmail.com"; x-sender="berke.durak@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ve0-f179.google.com) identity=helo; client-ip=209.85.128.179; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="berke.durak@gmail.com"; x-sender="postmaster@mail-ve0-f179.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoABAJS9Y1PRVYCzlGdsb2JhbABaDoNHWIJnwWKBCQgWDgEBAQEHCwsJEiqCJQEBBSMEGQEbHQEDDAYFCw0CAiYCAiIBEQEFARwGE4gsAQMRDZlhjBFRgw2ZLwoZJw1khWERAQUMgR6MdTMHgm+BSgSZMIE8j0IYKYQkXCEw X-IPAS-Result: AoABAJS9Y1PRVYCzlGdsb2JhbABaDoNHWIJnwWKBCQgWDgEBAQEHCwsJEiqCJQEBBSMEGQEbHQEDDAYFCw0CAiYCAiIBEQEFARwGE4gsAQMRDZlhjBFRgw2ZLwoZJw1khWERAQUMgR6MdTMHgm+BSgSZMIE8j0IYKYQkXCEw X-IronPort-AV: E=Sophos;i="4.97,973,1389740400"; d="scan'208";a="71697339" Received: from mail-ve0-f179.google.com ([209.85.128.179]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 May 2014 17:50:23 +0200 Received: by mail-ve0-f179.google.com with SMTP id oy12so2736408veb.10 for ; Fri, 02 May 2014 08:50:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=6wLL+eSkI7JZBJSVgKm9BaSPTAMBuDTvERKrzSWTlpA=; b=Vb3Gp/UOzQlSzmsKXICjmgSqpIJBelLty0c3Y/mx9M4RjZTGESrathn+ZT8UC26Nqw X+WegJAwowprSgrqs4Kx0s0l6GaWeZAehT/2ZdckljGARC/+b4XH0Ja8ugkhmIVsZd2D oTbBA36PKM59JvTyH68KOGZkHJZUiSOQxibR/X+meGIdKcFDahOdLU4CzvlsDXEc03Cu 5OW7Ft68rWzOqXQ+NFZuSNFZsaqToThxEWihekIs4/8fKFKKiv6CEuxw+mcJ0CykHdv0 +nxSti/39pZjCrYrnmci0zD5eN5tHG5ljlhwksZfXn9V8/WFd5CacLIX7b0tNLohXTW0 CraQ== MIME-Version: 1.0 X-Received: by 10.58.243.4 with SMTP id wu4mr507367vec.67.1399045822378; Fri, 02 May 2014 08:50:22 -0700 (PDT) Received: by 10.220.80.4 with HTTP; Fri, 2 May 2014 08:50:22 -0700 (PDT) In-Reply-To: <54FF3D28-6DAE-4C6A-B4B8-6D777570F3EB@math.nagoya-u.ac.jp> References: <54FF3D28-6DAE-4C6A-B4B8-6D777570F3EB@math.nagoya-u.ac.jp> Date: Fri, 2 May 2014 11:50:22 -0400 Message-ID: From: Berke Durak To: Jacques Garrigue Cc: Mailing List OCaml Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Trying to define a functor combining polymorphic variants Thanks Leo and Jacques for the responses. 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))))? 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 do= es: >> >> module type S =3D sig >> type message >> val string_of_message : message -> string >> end >> >> 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 >> >> 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 varian= t 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.messa= ge) =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 = some 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