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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 40D097F8BE for ; Thu, 1 May 2014 22:58:11 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of berke.durak@gmail.com) identity=pra; client-ip=209.85.128.178; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="berke.durak@gmail.com"; x-sender="berke.durak@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of berke.durak@gmail.com designates 209.85.128.178 as permitted sender) identity=mailfrom; client-ip=209.85.128.178; receiver=mail3-smtp-sop.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 (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ve0-f178.google.com) identity=helo; client-ip=209.85.128.178; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="berke.durak@gmail.com"; x-sender="postmaster@mail-ve0-f178.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApIBAG+0YlPRVYCylGdsb2JhbABahCyCZ8J/CBYOAQEBAQcLCwkSKoJPBBkBGx4DEhAPAiYCJAERAQUBIog/AQMRlmyDD4wRUYMNmHYKGScNZIVhEQEFDIEekB6BSgSZL5B9GCmEfyE X-IPAS-Result: ApIBAG+0YlPRVYCylGdsb2JhbABahCyCZ8J/CBYOAQEBAQcLCwkSKoJPBBkBGx4DEhAPAiYCJAERAQUBIog/AQMRlmyDD4wRUYMNmHYKGScNZIVhEQEFDIEekB6BSgSZL5B9GCmEfyE X-IronPort-AV: E=Sophos;i="4.97,966,1389740400"; d="scan'208";a="60046874" Received: from mail-ve0-f178.google.com ([209.85.128.178]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 01 May 2014 22:58:10 +0200 Received: by mail-ve0-f178.google.com with SMTP id jw12so4382919veb.23 for ; Thu, 01 May 2014 13:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=MxKRN+l/SLpLUK4wkP6gAEvF9qzedxBs/Pxsig6gKU8=; b=jFaOdxfM8c2szA8uYS201sCxL0sDqLAr6tnUQaiyHh+NRTUw0xUyiVkO4EkK+ast0r 9rC2Y2cxWJTyugfSWFKLJFF9NsLE4LFSZkzIRZMR9mRkgpBkR61YtAkch4CcnjvZEiAh EXmWe/tLmOcR3ONrUoYAFc0V0hBUfJRwskzdyVqUNtJLiJdh+DFsLQ32SxN+Vnguwtk0 APdYea/K+0Bbl7Zzb60qNkGE6/4/e2AxNbFTy1jg6ILe4YAMiNJZJND9qo196cna/ENB agd1/akcocm6U5/vXddlUS58s9hlJzUgDFzaUCjqk+FLysAMmHGJiZ5IWky6Ka6/lrUm JmMA== MIME-Version: 1.0 X-Received: by 10.221.40.193 with SMTP id tr1mr1451311vcb.31.1398977889256; Thu, 01 May 2014 13:58:09 -0700 (PDT) Received: by 10.220.80.4 with HTTP; Thu, 1 May 2014 13:58:09 -0700 (PDT) Date: Thu, 1 May 2014 16:58:09 -0400 Message-ID: From: Berke Durak To: caml-list Content-Type: text/plain; charset=UTF-8 Subject: [Caml-list] Trying to define a functor combining polymorphic variants Hello all, I have been using the following kind of construct: module A = struct type message = [`Alpha] let string_of_message = function `Alpha -> "alpha" end module B = struct type message = [`Beta] let string_of_message = function `Beta -> "beta" end module AB = struct type message = [ A.message | B.message ] let string_of_message = function | #A.message as msg -> A.string_of_message msg | #B.message as msg -> B.string_of_message msg end So I naturally wanted to write a functor that does what the module AB does: module type S = sig type message val string_of_message : message -> string end module PROD(A : S)(B : S) = struct type message = [ A.message | B.message ] let string_of_message = 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 variant so that [ A.message | B.message ] is legal. We tried things like: module type S = sig type 'a t = ([> ] as 'a) end module PROD(X : S)(Y : S) = struct type ('a,'b) t = [ 'a X.t | 'b Y.t ] end but all we get is: Error: The type [> ] A.message is not a polymorphic variant type Any suggestions? -- Berke Durak