caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Dumitru Potop-Butucaru <dumitru.potop_butucaru@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] How can I set a type parameter of Map.Make(X) ?
Date: Mon, 20 Sep 2010 10:58:23 -0700	[thread overview]
Message-ID: <4C97A0BF.1020003@ens-lyon.org> (raw)
In-Reply-To: <4C97991F.7030503@inria.fr>

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 =<fun>
>>
>>
>> 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


-- 
http://mjambon.com/


  parent reply	other threads:[~2010-09-20 17:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-20 14:35 Dumitru Potop-Butucaru
2010-09-20 14:57 ` [Caml-list] " Ashish Agarwal
2010-09-20 17:25   ` Dumitru Potop-Butucaru
2010-09-20 17:31     ` Ashish Agarwal
2010-09-20 17:58     ` Martin Jambon [this message]
2010-09-20 19:02       ` Dumitru Potop-Butucaru
2010-09-20 19:32         ` Ashish Agarwal
2010-09-20 19:35         ` code duplication (was Re: [Caml-list] How can I set a type parameter of Map.Make(X) ?) Martin Jambon
2010-09-20 14:59 ` How can I set a type parameter of Map.Make(X) ? Sylvain Le Gall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C97A0BF.1020003@ens-lyon.org \
    --to=martin.jambon@ens-lyon.org \
    --cc=caml-list@inria.fr \
    --cc=dumitru.potop_butucaru@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).