From: skaller <skaller@users.sourceforge.net>
To: Christopher L Conway <cconway@cs.nyu.edu>
Cc: caml-list@inria.fr, Jon Harrop <jon@ffconsultancy.com>
Subject: Re: [Caml-list] module interface?
Date: Tue, 31 Jul 2007 03:13:12 +1000 [thread overview]
Message-ID: <1185815592.8102.12.camel@rosella.wigram> (raw)
In-Reply-To: <4a051d930707300943h4d824dbxcc39b13db37cba46@mail.gmail.com>
On Mon, 2007-07-30 at 12:43 -0400, Christopher L Conway wrote:
> 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
Yes, it is quite logical I'm sure, but that wasn't the issue
so much as how someone would learn to use it, i.e. documentation
and tutorial. The tutorial on functors skips over this by
elaborating the signature of the resulting module.
This looks cute in the tutorial, but is out of the question
for even simple functors like Map.Make because they have
far too many methods.
If you try ocamlc -i .. it lists all those methods. Some years
ago I actually used that in the *.mli file. It turned me off
using functors. Later I learned:
module Drules : Map.S with type key = string
(and in fact already have several instances of that in my program,
which I forgot about).
Maybe Jon Harrop covers this well in his book?
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
next prev parent reply other threads:[~2007-07-30 17:13 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
2007-07-30 17:13 ` skaller [this message]
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=1185815592.8102.12.camel@rosella.wigram \
--to=skaller@users.sourceforge.net \
--cc=caml-list@inria.fr \
--cc=cconway@cs.nyu.edu \
--cc=jon@ffconsultancy.com \
/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