From: "Christopher L Conway" <cconway@cs.nyu.edu>
To: skaller <skaller@users.sourceforge.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] module interface?
Date: Mon, 30 Jul 2007 12:43:04 -0400 [thread overview]
Message-ID: <4a051d930707300943h4d824dbxcc39b13db37cba46@mail.gmail.com> (raw)
In-Reply-To: <1185782144.6753.13.camel@rosella.wigram>
On 7/30/07, skaller <skaller@users.sourceforge.net> wrote:
> On Mon, 2007-07-30 at 09:03 +0200, Benedikt Grundmann wrote:
> > module Drules : Map.S with type key = string
>
> So I discovered -- thanks! But hmm, this totally counter intuitive!
>
> You call Map.Make, but refer to Map.S.
> The supplied key is with
>
> type t = string
>
> but in the sig you use
>
> type key = string
>
> and finally the
>
> let compare = compare
>
> in the module is simply dropped.
>
> There is no example of this in the tutorial..
> how would I every guess at the right solution?
Map.Make has functor type (Map.OrderedType -> Map.S), so a module
Map.Make( Ord ) will have module type Map.S. Further, the type of
Map.Make has the restriction that Map.Make( Ord ).key = Ord.t. Since
the identity of Ord is hidden in your .mli, you have to expose it with
your own restriction (if it matters, which it probably does), thus:
module Drules : Map.S with type key = string
The function Ord.compare is "dropped" (hidden, really) because it's
not part of the module type Map.S. You could write your own functor
that exposes it (note that "compare" is bound in Map.S to the function
which compares two maps):
# module type MyMapS = sig
include Map.S
val compare_keys : key -> key -> int
end ;;
module type MyMapS =
sig
type key
type +'a t
val empty : 'a t
val is_empty : 'a t -> bool
val add : key -> 'a -> 'a t -> 'a t
val find : key -> 'a t -> 'a
val remove : key -> 'a t -> 'a t
val mem : key -> 'a t -> bool
val iter : (key -> 'a -> unit) -> 'a t -> unit
val map : ('a -> 'b) -> 'a t -> 'b t
val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
val compare_keys : key -> key -> int
end
# module MyMap( Ord : Map.OrderedType ) = struct
module M = Map.Make( Ord )
open M
let compare_keys = Ord.compare
end ;;
module MyMap :
functor (Ord : Map.OrderedType) ->
sig
module M :
sig
type key = Ord.t
type 'a t = 'a Map.Make(Ord).t
val empty : 'a t
val is_empty : 'a t -> bool
val add : key -> 'a -> 'a t -> 'a t
val find : key -> 'a t -> 'a
val remove : key -> 'a t -> 'a t
val mem : key -> 'a t -> bool
val iter : (key -> 'a -> unit) -> 'a t -> unit
val map : ('a -> 'b) -> 'a t -> 'b t
val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
end
val compare_keys : Ord.t -> Ord.t -> int
end
Regards,
Chris
next prev parent reply other threads:[~2007-07-30 16:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-30 6:45 skaller
2007-07-30 7:03 ` [Caml-list] " Benedikt Grundmann
2007-07-30 7:55 ` skaller
2007-07-30 8:02 ` Benedikt Grundmann
2007-07-30 8:16 ` skaller
2007-07-30 16:43 ` Christopher L Conway [this message]
2007-07-30 17:13 ` skaller
2007-07-30 19:24 ` Jon Harrop
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=4a051d930707300943h4d824dbxcc39b13db37cba46@mail.gmail.com \
--to=cconway@cs.nyu.edu \
--cc=caml-list@inria.fr \
--cc=skaller@users.sourceforge.net \
/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