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 61CC97EE11 for ; Wed, 20 Aug 2014 20:38:20 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of darioteixeira@yahoo.com) identity=pra; client-ip=98.138.91.235; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="darioteixeira@yahoo.com"; x-sender="darioteixeira@yahoo.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of darioteixeira@yahoo.com designates 98.138.91.235 as permitted sender) identity=mailfrom; client-ip=98.138.91.235; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="darioteixeira@yahoo.com"; x-sender="darioteixeira@yahoo.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@nm13-vm5.bullet.mail.ne1.yahoo.com) identity=helo; client-ip=98.138.91.235; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="darioteixeira@yahoo.com"; x-sender="postmaster@nm13-vm5.bullet.mail.ne1.yahoo.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al4BAPrp9FNiilvrm2dsb2JhbABahDcECLIMoyAWEAEBAQEBBgsLCRQpg34XHAQVARciFXoBDgEGGC6IEgEBAhEEnXORIQmDB4F9iEcBIwMBIwOFKBEGDAIBlBAFiyKRKYcmN2OKaXOEZEyCTwEBAQ X-IPAS-Result: Al4BAPrp9FNiilvrm2dsb2JhbABahDcECLIMoyAWEAEBAQEBBgsLCRQpg34XHAQVARciFXoBDgEGGC6IEgEBAhEEnXORIQmDB4F9iEcBIwMBIwOFKBEGDAIBlBAFiyKRKYcmN2OKaXOEZEyCTwEBAQ X-IronPort-AV: E=Sophos;i="5.01,903,1400018400"; d="scan'208";a="90086998" Received: from nm13-vm5.bullet.mail.ne1.yahoo.com ([98.138.91.235]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Aug 2014 20:38:19 +0200 Received: from [98.138.226.179] by nm13.bullet.mail.ne1.yahoo.com with NNFMP; 20 Aug 2014 18:38:17 -0000 Received: from [98.138.226.165] by tm14.bullet.mail.ne1.yahoo.com with NNFMP; 20 Aug 2014 18:38:16 -0000 Received: from [127.0.0.1] by omp1066.mail.ne1.yahoo.com with NNFMP; 20 Aug 2014 18:38:16 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 192192.54175.bm@omp1066.mail.ne1.yahoo.com Received: (qmail 75128 invoked by uid 60001); 20 Aug 2014 18:38:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1408559896; bh=vH0bhnU9cMB3iQ49kRy8vdI5+Ju8vC7NYnoNyVeFVDw=; h=Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=tLxh3+StsXhRrLTRP5IdU+KeIbpSTimTmJjS4Mtu7dFxyYRyWQYBOc2wCTgN6pfJHEQNXk/azWRxG3zRvIuOJWVG3dPSIQq+z0xqDrBNB8dNdA1u+23LbCjquv6EvJIfTstw6mbcUswreCfh4t3FvrP3EnV5qrIRrs828sf11Xs= X-YMail-OSG: cbW7OXwVM1nO7UDh1vi2dRMnk.J8j_Izr1loFdZ1P9afNOG c5kGSfNLzZ1YaeKPREbdaZDlwJrEZLRvCS9cxshFUnad.8Y7KmPSj9mjLcbL 7CA6gpqz_bBW1UvCy9rxrdX1R4YdPWEpj7F6wEhZ.Ngeuxa3dOEb8SLxOX4K ZQq9oglVD4vT2fbFVoTyixOyE5XK2FgmMv65EzqKZY5ddWFN7nO4P9M55jsS R0qIubVUo9DaAz3AOESZm7tORGRhPtaZTQdIXwSu4o2s0BwBbc6Ak8C9dg7a nSL5ppBVFvQXUUjiP4z9WriQQWPNXRagsbVzGX_prL2ouQj.1BazNtJ1Hqg4 dRFjxWepHmAKoq04zM7_nVKg.9spKZbBXC38Iov.N39kot6HOW5Hs6.EFlIO 55KEIbZYvEmbkpMEboFNSumNsC9YWwXkcUFvSxpSiHMYImOkCBKEf8fYitwB K5N3mnn7BA2rEdu35AT160425RauADUiVuuYLAyre3_TNBDxRsmgyJsvlvs2 gltXKyGKma8VtyadFGjWPFniarC2sQ5xGc1LjHvKiYx9dsAFRYbb_0_mCcaH wVQ-- Received: from [178.166.105.209] by web121705.mail.ne1.yahoo.com via HTTP; Wed, 20 Aug 2014 11:38:16 PDT X-Rocket-MIMEInfo: 002.001,SGksCgpDb25zaWRlciB0aGUgc2lnbmF0dXJlIExPR0dFUiBiZWxvdywgdG8gYmUgaW1wbGVtZW50ZWQgYnkgYW55IG1vZHVsZSB0aGF0CnN1cHBvc2VkbHkgbG9ncyBzb21ldGhpbmcgd3JhcHBlZCB1bmRlciBhIGN1c3RvbSBtb25hZDoKCsKgIG1vZHVsZSB0eXBlIExPR0dFUiA9CsKgIHNpZwrCoMKgwqDCoMKgIG1vZHVsZSBNb25hZDoKwqDCoMKgwqDCoCBzaWcKwqDCoMKgwqDCoMKgwqDCoMKgIHR5cGUgJ2EgdArCoMKgwqDCoMKgwqDCoMKgwqAgdmFsIHJldHVybjogJ2EgLT4gJ2EgdArCoMKgwqDCoMKgwqABMAEBAQE- X-Mailer: YahooMailWebService/0.8.201.700 Message-ID: <1408559896.43780.YahooMailNeo@web121705.mail.ne1.yahoo.com> Date: Wed, 20 Aug 2014 11:38:16 -0700 From: Dario Teixeira Reply-To: Dario Teixeira To: OCaml mailing-list MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Subject: [Caml-list] Locally abstract type with type parameters Hi, Consider the signature LOGGER below, to be implemented by any module that supposedly logs something wrapped under a custom monad: =A0 module type LOGGER =3D =A0 sig =A0=A0=A0=A0=A0 module Monad: =A0=A0=A0=A0=A0 sig =A0=A0=A0=A0=A0=A0=A0=A0=A0 type 'a t =A0=A0=A0=A0=A0=A0=A0=A0=A0 val return: 'a -> 'a t =A0=A0=A0=A0=A0=A0=A0=A0=A0 val bind: 'a t -> ('a -> 'b t) -> 'b t =A0=A0=A0=A0=A0 end =A0=A0=A0=A0=A0 val log: unit -> unit Monad.t =A0 end We now define a functor that takes a LOGGER and defines a 'process' function that operates under the monad.=A0 But here's the twist: suppose that the fu= nction that actually does the processing is defined elsewhere, in a module 'Foo'. Moreover, instead of passing it the functions of the logger as independent parameters, we deem it more convenient to pass the logger as a first-class module: =A0 module Make (Logger: LOGGER) =3D =A0 struct =A0=A0=A0=A0=A0 let process x =3D Foo.actually_process (module Logger: LOGG= ER) x =A0 end To avoid type-escaping-its-scope errors, we need to define a locally abstra= ct type in the implementation of 'actually_process'.=A0 Something like this: =A0 let actually_process (type u) (module Logger: LOGGER with type 'a Monad= .t =3D 'a u) x =3D =A0=A0=A0=A0=A0 let open Logger in =A0=A0=A0=A0=A0 let (>>=3D) t f =3D Monad.bind t f in =A0=A0=A0=A0=A0 Logger.log () >>=3D fun () -> =A0=A0=A0=A0=A0 Monad.return x Which does not actually compile.=A0 Is it at all possible to use a locally abstract type when that type has type parameters?=A0 And is there a solution to this problem that does not require a) moving the implementation of 'actually_process' to the inside of a functor, or b) pass each function of the first-class module as a separate parameter to 'actually_process'? Thanks in advance for your time! Best regards, Dario Teixeira