Browse thread
[Caml-list] newbie type problem
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Andrew Lenharth <andrewl@d...> |
| Subject: | Re: [Caml-list] newbie type problem |
> 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