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 5F755820A1 for ; Mon, 12 Aug 2013 12:21:05 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of yallop@gmail.com) identity=pra; client-ip=209.85.212.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of yallop@gmail.com designates 209.85.212.176 as permitted sender) identity=mailfrom; client-ip=209.85.212.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="yallop@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-wi0-f176.google.com) identity=helo; client-ip=209.85.212.176; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yallop@gmail.com"; x-sender="postmaster@mail-wi0-f176.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AoICAO+1CFLRVdSwjmdsb2JhbABahAuDE7tDgRIIFg4BAQEBBw0JCRIGJIIkAQEFIwQZARsdAQMMBgULDQICJgICIgERAQUBHAYTh30BAw+ZCYwAUYMChAQKGScNZId0AQUMgR2PEgeCaIEpA5dkj2wWKYRCOw X-IPAS-Result: AoICAO+1CFLRVdSwjmdsb2JhbABahAuDE7tDgRIIFg4BAQEBBw0JCRIGJIIkAQEFIwQZARsdAQMMBgULDQICJgICIgERAQUBHAYTh30BAw+ZCYwAUYMChAQKGScNZId0AQUMgR2PEgeCaIEpA5dkj2wWKYRCOw X-IronPort-AV: E=Sophos;i="4.89,861,1367964000"; d="scan'208";a="29121822" Received: from mail-wi0-f176.google.com ([209.85.212.176]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 12 Aug 2013 12:20:32 +0200 Received: by mail-wi0-f176.google.com with SMTP id f14so1487032wiw.15 for ; Mon, 12 Aug 2013 03:20:17 -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; bh=x6SFsaRxX7NVFGLkuJGM+2WxRarOcyyrqjY7iKjvU1M=; b=m5Kj9jwVLKsMvsDzu+FtjNj5vVs/xa90XT7RhiA46WPcRhOlQ4OuiSWi9Ef4MwR8XQ BZmH5QZinqqJbjPVMlA3vatL6HvWh8Fihz57fw6jPubTPJefseD8Y9fdiO6/Te1pgM4n CCePid1dHakOq9QK3tH/VXN9BGXUqcMH6rI33DbA3ItSf3Ua9ZlFqTAmgs8dnhxCrabD E25IjBeZv5bmwnUf9xf3Aphb9ibNJYRUXCHi5kYdkOzFaOShpgWpFEdOV2saOet/Ti5Y AwSa/PfIFfshbsXm9LC8B/ADr5a3UWwB6hijVNNamBWXLOCEqHBsk8U5FQufJMti2ELG +Jcg== MIME-Version: 1.0 X-Received: by 10.194.78.18 with SMTP id x18mr11944580wjw.93.1376302817662; Mon, 12 Aug 2013 03:20:17 -0700 (PDT) Received: by 10.216.169.7 with HTTP; Mon, 12 Aug 2013 03:20:17 -0700 (PDT) In-Reply-To: <20130812074545.GA4646@kerneis.info> References: <20130812074545.GA4646@kerneis.info> Date: Mon, 12 Aug 2013 11:20:17 +0100 Message-ID: From: Jeremy Yallop To: Gabriel Kerneis Cc: caml-list@yquem.inria.fr Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Signature substitution and type parameters On 12 August 2013 08:45, Gabriel Kerneis wrote: > Is there a concise way to instanciate a module containing a parametric > type for a particular value of this type parameter? > > module type Poly = sig type 'a t val f : 'a t -> 'a t end ;; > module type Mono = sig type t val f : t -> t end ;; > > module PolyM : Poly = struct type 'a t let f x = x end ;; > > The following works but is tedious when Poly contains many functions > instead of only one: > > module MonoM : Mono = struct > open PolyM > type t = int PolyM.t > let f = PolyM.f > end ;; If you use 'include' instead of 'let' it generalizes nicely to the many-function case: module MonoM : Mono = struct type t = int PolyM.t include (PolyM : Mono with type t := t) end A slight variation makes it possible to achieve a similar effect without using the Mono signature: type _ s = int PolyM.t module MonoM = struct type t = unit s include (PolyM : Poly with type 'a t := 'a s) end Your other approach can be made to work, too. The key is to define a type alias with no parameters (type t = int PolyM.t), then use destructive substitution (:=).