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 DC472820A1 for ; Mon, 12 Aug 2013 11:57:54 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of raphlalou@gmail.com) identity=pra; client-ip=209.85.223.174; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="raphlalou@gmail.com"; x-sender="raphlalou@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of raphlalou@gmail.com designates 209.85.223.174 as permitted sender) identity=mailfrom; client-ip=209.85.223.174; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="raphlalou@gmail.com"; x-sender="raphlalou@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-ie0-f174.google.com) identity=helo; client-ip=209.85.223.174; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="raphlalou@gmail.com"; x-sender="postmaster@mail-ie0-f174.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvcBAEGxCFLRVd+um2dsb2JhbABaFoMlUIMTqRySJ4ESCBYOAQEBAQEGCwsJFCiCJAEBBSMEGQEbEgsBAwwGBQsNAgIJHQICIgERAQUBChIGExKHawEDDwyYfowAUYMChAQKGScDCmSHdAEFDIEdjDqCJTMHgmiBKQOXZIEsjkAWKYRCOw X-IPAS-Result: AvcBAEGxCFLRVd+um2dsb2JhbABaFoMlUIMTqRySJ4ESCBYOAQEBAQEGCwsJFCiCJAEBBSMEGQEbEgsBAwwGBQsNAgIJHQICIgERAQUBChIGExKHawEDDwyYfowAUYMChAQKGScDCmSHdAEFDIEdjDqCJTMHgmiBKQOXZIEsjkAWKYRCOw X-IronPort-AV: E=Sophos;i="4.89,861,1367964000"; d="scan'208";a="29117607" Received: from mail-ie0-f174.google.com ([209.85.223.174]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 12 Aug 2013 11:57:47 +0200 Received: by mail-ie0-f174.google.com with SMTP id w15so7814528iea.19 for ; Mon, 12 Aug 2013 02:57:47 -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=rKkwUksfZTcR0eIhStNGkHuuDFFETVun97EOlkEJlz4=; b=Awks3JbnuYIbSN5Ldme42rQdsHRK0JsP0+SMu0jiwwE/7CxGwmIY4umxfMo9uTwo40 vofe31liKC7ZkOV9gxW1rffo6H6V1lB3NSXeUnt5Hew47z12au85BBejmKlVN2KYFrL7 yS0BobXVDK7ljsrscQOQkG6WgDnqlxkQGiGLLiPSeehRbjE9y7G6WbByRsa926YSWGOL La+jmx9QRi+POISwX8GJMnacDDDXMId025B8RGpn26FsMeF/q9YCIBT1qhdpNqSOk38j xoZQep5LwnaNbZ0wc8lXmNB2y2yH0ZMuOyPl64Y8Mz/uMzEh2uBcft3PiC0GKcaxIgtp +xiA== MIME-Version: 1.0 X-Received: by 10.42.197.74 with SMTP id ej10mr8902944icb.80.1376301467116; Mon, 12 Aug 2013 02:57:47 -0700 (PDT) Received: by 10.42.192.74 with HTTP; Mon, 12 Aug 2013 02:57:47 -0700 (PDT) In-Reply-To: <20130812074545.GA4646@kerneis.info> References: <20130812074545.GA4646@kerneis.info> Date: Mon, 12 Aug 2013 10:57:47 +0100 Message-ID: From: =?UTF-8?Q?Rapha=C3=ABl_Proust?= To: Gabriel Kerneis Cc: caml-list@yquem.inria.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] Signature substitution and type parameters Unsuccessful attempts with functors and type constraints: # module Monomorphise (P: Poly) (T: sig type t end) =3D struct type 'a t =3D T.t constraint 'a =3D int Interrupted. # module Monomorphise (P: Poly) (T: sig type t end) =3D struct type 'a t constraint 'a =3D T.t include (P : Poly with type 'a t :=3D 'a t constraint 'a =3D T.t) end ;; Syntax error: ')' expected, the highlighted '(' might be unmatched # module Monomorphise (P: Poly) (T: sig type t end) =3D struct type 'a t constraint 'a =3D T.t include (P : Poly with type 'a t :=3D 'a t) end ;; Error: In this `with' constraint, the new definition of t does not match its original definition in the constrained signature: Type declarations do not match: type 'a t =3D 'a t constraint 'a =3D T.t is not included in type 'a t Their constraints differ. On Mon, Aug 12, 2013 at 8:45 AM, Gabriel Kerneis wro= te: > Dear all, > > Is there a concise way to instanciate a module containing a parametric > type for a particular value of this type parameter? > > module type Poly =3D sig type 'a t val f : 'a t -> 'a t end ;; > module type Mono =3D sig type t val f : t -> t end ;; > > module PolyM : Poly =3D struct type 'a t let f x =3D x end ;; > > The following works but is tedious when Poly contains many functions > instead of only one: > > module MonoM : Mono =3D struct > open PolyM > type t =3D int PolyM.t > let f =3D PolyM.f > end ;; > > My other attempts so far: > > # module MonoM : (Mono with type t :=3D int PolyM.t) =3D PolyM ;; > Error: Only type constructors with identical parameters can be > substituted. > > # module MonoM : (Mono with type t =3D int PolyM.t) =3D PolyM ;; > Error: Signature mismatch: > Modules do not match: > sig type 'a t =3D 'a PolyM.t val f : 'a t -> 'a t end > is not included in > sig type t =3D int PolyM.t val f : t -> t end > Type declarations do not match: > type 'a t =3D 'a PolyM.t > is not included in > type t =3D int PolyM.t > They have different arities. > > Is this a fundamental limitation of the typechecker, which would > otherwise lead to unsafe behaviour? > > Note: The initial motivation for doing this was to use Jean-Christophe > Filli=C4=81tre's Hset as a drop-in replacement for OCaml's Set in one o= f my > programs, without having to add type parameters all over the place. > https://www.lri.fr/~filliatr/ftp/ocaml/ds/hset.mli.html > > Kind regards, > -- > Gabriel > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs --=20 ______________ Rapha=C3=ABl Proust