Version française
Home     About     Download     Resources     Contact us    
Browse thread
How to use Set Datatype
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Micha <micha-1@f...>
Subject: Re: [Caml-list] How to use Set Datatype
Am Freitag, 10. Dezember 2004 19:37 schrieb Jan Stamer:
> Hi all,
>
> I am new to Ocaml and for the past hour I tried to figure out how to use
> the built-in Set Datatype.

:-) easy to spend time with this ...

> I would like to use a set of Strings. Can anybody help me and give me a
> few lines of sample code?

you have to make a module first, which holds the type and the order function 
for your set:

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

now you can use it (silly example :-)

let set_example str = 
 let set = StringSet.empty in    (* make new set *) 
 let set = StringSet.add set str in
StringSet.mem set "xxx";;    


cheers
 Michael