Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] newbie type problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi Vanicat <vanicat@l...>
Subject: Re: [Caml-list] newbie type problem
Andrew Lenharth <andrewl@debian.org> writes:

>> 	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.

Yes you can.

In recent caml you might even do :

module StringSet = Set.Make (String)

It work because in the stdlib's String module there is a type t equal to
string, and a compare function.


-- 
Rémi Vanicat

-------------------
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