caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Andrew Lenharth <andrewl@debian.org>
To: Dustin Sallings <dustin@spy.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] newbie type problem
Date: Fri, 24 Oct 2003 08:49:58 -0400	[thread overview]
Message-ID: <20031024124958.GA15981@vilya.homelinux.net> (raw)
In-Reply-To: <087CB9D7-05FB-11D8-B1A2-000393DC8AE4@spy.net>

> 	Yeah, but I still couldn't figure out how to make a Map, assuming 
> that's what I really wanted in the first place.  A hash table that 
> iterates in key sorted order would make my app faster and reduce 
> complexity.  I want to see it actually work first, though.  :)

Yes, making a map is non-obvious.  One first has to figure out the 
module system, with no examples.  Here is a hint:

module StringSet = Set.Make(struct type t = string let compare x y = 
compare x y end)

then you can do things like
StringSet.mem n1 set;;
StringSet.union s1 s2;;
StringSet.add x StringSet.empty;;

BTW: I am sure you can do the compare without the x y by 
compare=compare.

A bit about what is going on.  Set is a parameratized module which you 
must narrow to what you want.  So you use the Make function to return a 
module with the types you want.  They you can use this module in your 
code.

Good examples of this are few and far between.

Andrew Lenharth

-- 
"The reasonable man adapts himself to the world; the unreasonable 
one persists in trying to adapt the world to 
himself. Therefore all progress depends on the unreasonable man."
-- George Bernard Shaw

No matter how cynical you become, it's never enough to keep up.
-- Lily Tomlin

Fools ignore complexity; pragmatists suffer it; experts avoid it; 
geniuses remove it.
-- A. Perlis

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2003-10-24 12:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-24  6:11 Dustin Sallings
2003-10-23 23:32 ` David Brown
2003-10-24  6:54   ` Dustin Sallings
2003-10-24  0:52     ` David Brown
2003-10-24  8:21       ` Dustin Sallings
2003-10-24 12:49         ` Andrew Lenharth [this message]
2003-10-24 13:22           ` Remi Vanicat
2003-10-29  7:23         ` Florian Hars
2003-10-29  8:03           ` Dustin Sallings
2003-10-29 16:27             ` Florian Hars
2003-10-24  9:25     ` Hendrik Tews
2003-10-24 16:23       ` Dustin Sallings

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=20031024124958.GA15981@vilya.homelinux.net \
    --to=andrewl@debian.org \
    --cc=caml-list@inria.fr \
    --cc=dustin@spy.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;
as well as URLs for NNTP newsgroup(s).