From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id ED9CABC57 for ; Mon, 20 Sep 2010 21:32:55 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtwBAM1Tl0zRVdY2kGdsb2JhbACBRZIyhg4BiA0IFQEBAQEJCQwHEQMfp2+JPIIUhlYuiDgBAQMFhTwEgVqDKoU0 X-IronPort-AV: E=Sophos;i="4.56,395,1280700000"; d="scan'208";a="68058020" Received: from mail-bw0-f54.google.com ([209.85.214.54]) by mail1-smtp-roc.national.inria.fr with ESMTP; 20 Sep 2010 21:32:55 +0200 Received: by bwz15 with SMTP id 15so7551343bwz.27 for ; Mon, 20 Sep 2010 12:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type; bh=TgELlZ0locUavS1kNV0+0A525SOQ9McHfSs9sGhiwQw=; b=RjOKj0YpGesn/OivKb1/E413KX/zs2X1u5inEGBpYgRzawGvycpbWbZygwzVWm5LYW 8ZRQih+YeLJV3yOriJeY7NBAzAgASqS3m5Uae1O82wDKR7i/IZNFIaP/Y0/it6tTDd0O 90a4nzcpx1q0TGrcLW4HY1gckabKRH/Acl2O0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=Ac1bSlfqFUwyAAwqoxTLgnazVneaCgo0mStygQntipvwKbDiQq33fwec+z3ppgvHnb Ex8mwjjGq2LtxxXtTTP1ps5Xv2JcKKMRRjhrG395t/TDWIONlg0T2XUclb+fQQrO1qW1 f/kuRNUZ17vgQWHNeuIzdf89srM4AGp100JkU= Received: by 10.204.98.135 with SMTP id q7mr7198316bkn.49.1285011175162; Mon, 20 Sep 2010 12:32:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.82.166 with HTTP; Mon, 20 Sep 2010 12:32:35 -0700 (PDT) In-Reply-To: <4C97AFE2.9000809@inria.fr> References: <4C97714A.6050403@inria.fr> <4C97991F.7030503@inria.fr> <4C97A0BF.1020003@ens-lyon.org> <4C97AFE2.9000809@inria.fr> From: Ashish Agarwal Date: Mon, 20 Sep 2010 15:32:35 -0400 Message-ID: Subject: Re: [Caml-list] How can I set a type parameter of Map.Make(X) ? To: Dumitru Potop-Butucaru Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=001485f5e13aa0c4690490b5fa0e X-Spam: no; 0.00; mli:01 val:01 val:01 iter:01 foo:01 mli:01 bool:01 bool:01 iter:01 foo:01 int's:01 browsed:01 beginner's:01 ocaml:01 bug:01 --001485f5e13aa0c4690490b5fa0e Content-Type: text/plain; charset=ISO-8859-1 How about this: --- a.mli --- type map val fold : (string -> int -> 'a -> 'a) -> map -> 'a -> 'a val iter : (string -> int -> unit) -> map -> unit --- a.ml --- module M = Map.Make(String) type map = int M.t include M You avoid boilerplate in the implementation, but I don't know how to avoid writing out the restricted types in the signature. On Mon, Sep 20, 2010 at 3:02 PM, Dumitru Potop-Butucaru < dumitru.potop_butucaru@inria.fr> wrote: > > Yes, but this involves duplicating code, and I really hate to duplicate > code, even in interfaces. > > To also answer Ashish: I want to define an interface to modules where I use > a very specific kind of map. Of course, I could leave Map.Make polymorphic, > but that is a different module type than the one I want to use to represent > my theory. > > Yours, > Jacky > > > > On 20/09/2010 19:58, Martin Jambon wrote: > >> Dumitru Potop-Butucaru wrote: >> >>> Actually, I was looking for a way to specialize a whole module, >>> not just the associated type (**this** I knew how to do). >>> I would like to write something like: >>> >>> include module type of Set.Make(String) with 'a= int >>> >>> Is this possible? >>> >> I don't know about such a shortcut, but the following works and the >> interface >> is easier to use for a human: >> >> (* foo.mli *) >> type key = string >> type value = string >> type map >> val empty : map >> val is_empty : map -> bool >> val add : key -> value -> map -> map >> val find : key -> map -> value >> val remove : key -> map -> map >> val mem : key -> map -> bool >> val iter : (key -> value -> unit) -> map -> unit >> val map : (value -> value) -> map -> map >> val mapi : (key -> value -> value) -> map -> map >> val fold : (key -> value -> 'a -> 'a) -> map -> 'a -> 'a >> val compare : (value -> value -> int) -> map -> map -> int >> val equal : (value -> value -> bool) -> map -> map -> bool >> >> >> (* foo.ml *) >> module M = Map.Make (String) >> include M >> type value = string >> type map = string M.t >> >> >> >> Martin >> >> >> Yours, >>> Jacky Potop >>> >>> >>> >>> >>> On 20/09/2010 16:57, Ashish Agarwal wrote: >>> >>>> module M = Map.Make(String) >>>> >>>> type t = int M.t >>>> >>>> Type t is the type of maps from string's to int's. Or alternatively >>>> write a >>>> function that assumes 'a is some specific type: >>>> >>>> # let f m = M.fold (fun _ x y -> x + y) m 0;; >>>> val f : int M.t -> int = >>>> >>>> >>>> On Mon, Sep 20, 2010 at 10:35 AM, Dumitru Potop-Butucaru< >>>> dumitru.potop_butucaru@inria.fr> wrote: >>>> >>>> Hello, >>>>> >>>>> I'm certain most users here will consider the question trivially >>>>> simple, >>>>> but I browsed the documentation without finding a solution. >>>>> >>>>> The question is quite general: Given a polymorphic definition like >>>>> Map.Make(X), where >>>>> X is some module, how can I specialize its 'a type parameter, e.g. by >>>>> setting it to Y, so that >>>>> I have maps from X to Y ? >>>>> >>>>> Yours, >>>>> Jacky Potop >>>>> >>>>> _______________________________________________ >>>>> Caml-list mailing list. Subscription management: >>>>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list >>>>> Archives: http://caml.inria.fr >>>>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >>>>> Bug reports: http://caml.inria.fr/bin/caml-bugs >>>>> >>>>> >>>>> _______________________________________________ >>> Caml-list mailing list. Subscription management: >>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list >>> Archives: http://caml.inria.fr >>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >>> Bug reports: http://caml.inria.fr/bin/caml-bugs >>> >> >> > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --001485f5e13aa0c4690490b5fa0e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
How about this:=

--- a.mli ---
type map

val fold : (string -> int -> 'a= -> 'a) -> map -> 'a -> 'a
val iter : (st= ring -> int -> unit) -> map -> unit

--- a.ml ---
module M =3D Map.Ma= ke(String)
type map =3D int M.t
include M

You avoid boilerplate in the implementation, but I don= 9;t know how to avoid writing out the restricted types in the signature.




On Mon, Sep 20, 2010 at 3:= 02 PM, Dumitru Potop-Butucaru <dumitru.potop_butucaru@inria.fr> = wrote:

Yes, but this involves duplicating code, and I really hate to duplicate cod= e, even in interfaces.

To also answer Ashish: I want to define an interface to modules where I use= a very specific kind of map. Of course, I could leave Map.Make polymorphic= , but that is a different module type than the one I want to use to represe= nt my theory.

Yours,
Jacky



On 20/09/2010 19:58, Martin Jambon wrote:
Dumitru Potop-Butucaru wrote:
Actually, I was looking for a way to specialize a whole module,
not just the associated type (**this** I knew how to do).
I would like to write something like:

=A0 =A0 include module type of Set.Make(String) with 'a=3D int

Is this possible?
I don't know about such a shortcut, but the following works and the int= erface
is easier to use for a human:

(* foo.mli *)
type key =3D string
type value =3D string
type map
val empty : map
val is_empty : map -> =A0bool
val add : key -> =A0value -> =A0map -> =A0map
val find : key -> =A0map -> =A0value
val remove : key -> =A0map -> =A0map
val mem : key -> =A0map -> =A0bool
val iter : (key -> =A0value -> =A0unit) -> =A0map -> =A0unit val map : (value -> =A0value) -> =A0map -> =A0map
val mapi : (key -> =A0value -> =A0value) -> =A0map -> =A0map val fold : (key -> =A0value -> =A0'a -> =A0'a) -> =A0ma= p -> =A0'a -> =A0'a
val compare : (value -> =A0value -> =A0int) -> =A0map -> =A0map= -> =A0int
val equal : (value -> =A0value -> =A0bool) -> =A0map -> =A0map = -> =A0bool


(* foo.ml *)
module M =3D Map.Make (String)
include M
type value =3D string
type map =3D string M.t



Martin


Yours,
Jacky Potop




On 20/09/2010 16:57, Ashish Agarwal wrote:
module M =3D Map.Make(String)

type t =3D int M.t

Type t is the type of maps from string's to int's. Or alternatively=
write a
function that assumes 'a is some specific type:

# let f m =3D M.fold (fun _ x y -> =A0 x + y) m 0;;
val f : int M.t -> =A0 int =3D<fun>


On Mon, Sep 20, 2010 at 10:35 AM, Dumitru Potop-Butucaru<
dumitr= u.potop_butucaru@inria.fr> =A0 wrote:

Hello,

I'm certain most users here will consider the question trivially simple= ,
but I browsed the documentation without finding a solution.

The question is quite general: Given a polymorphic definition like
Map.Make(X), where
X is some module, how can I specialize its 'a type parameter, e.g. by setting it to Y, so that
I have maps from X to Y ?

Yours,
Jacky Potop

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.in= ria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.in= ria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.in= ria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--001485f5e13aa0c4690490b5fa0e--