English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2004-12-10 (19:44)
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

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