From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA12378; Fri, 24 Oct 2003 14:50:08 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA08455 for ; Fri, 24 Oct 2003 14:50:06 +0200 (MET DST) Received: from ohsmtp03.ogw.rr.com (ohsmtp03.ogw.rr.com [65.24.7.38]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h9OCo4114064 for ; Fri, 24 Oct 2003 14:50:04 +0200 (MET DST) Received: from vilya (cpe-024-033-201-104.columbus.rr.com [24.33.201.104]) by ohsmtp03.ogw.rr.com (8.12.10/8.12.2) with ESMTP id h9OCnwFQ019842; Fri, 24 Oct 2003 08:49:58 -0400 (EDT) Received: from andrewl by vilya with local (Exim 3.36 #1 (Debian)) id 1AD1OA-0004AT-00; Fri, 24 Oct 2003 08:49:58 -0400 Date: Fri, 24 Oct 2003 08:49:58 -0400 From: Andrew Lenharth To: Dustin Sallings Cc: caml-list@inria.fr Subject: Re: [Caml-list] newbie type problem Message-ID: <20031024124958.GA15981@vilya.homelinux.net> References: <20031024005258.GA5049@davidb.org> <087CB9D7-05FB-11D8-B1A2-000393DC8AE4@spy.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <087CB9D7-05FB-11D8-B1A2-000393DC8AE4@spy.net> User-Agent: Mutt/1.5.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 newbie:01 hash:01 iterates:01 non-obvious:01 stringset:01 struct:01 stringset:01 lily:99 complexity:02 complexity:02 module:03 module:03 string:03 btw:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > 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