From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 12F61BB91 for ; Wed, 26 Jan 2005 15:07:26 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j0QE7PdN010382 for ; Wed, 26 Jan 2005 15:07:25 +0100 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 PAA08733 for ; Wed, 26 Jan 2005 15:07:25 +0100 (MET) Received: from sys26.mail.msu.edu (sys26.mail.msu.edu [35.9.75.126]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j0QE7NCF010373 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 26 Jan 2005 15:07:24 +0100 Received: from [24.56.225.152] (helo=gft) by sys26.mail.msu.edu with esmtpsa (Exim 4.43 #1) (TLSv1:RC4-MD5:128) id 1CtnpK-0001XL-Cp; Wed, 26 Jan 2005 09:07:22 -0500 Message-ID: <002201c503b0$5fb65740$6600a8c0@gft> From: "Jeff Shaw" To: Cc: Subject: Re: 'a Set? Date: Wed, 26 Jan 2005 09:07:00 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_001F_01C50386.654FB270" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus: None found by Clam AV X-Miltered: at concorde with ID 41F7A41D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41F7A41B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; rec:01 rec:01 inefficient:01 inefficient:01 functions:01 functions:01 hoc:02 hoc:02 arial:96 arial:96 terribly:03 terribly:03 let:03 let:03 elements:05 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=HTML_60_70,HTML_MESSAGE autolearn=disabled version=3.0.0 X-Spam-Level: This is a multi-part message in MIME format. ------=_NextPart_000_001F_01C50386.654FB270 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Mike, I know of no way to do what you're asking for. However, you can always = use lists as an ad hoc kind of set. Use List.mem to check membership, = and some functions to add elements or create a set while looking for = duplicates: let add n list =3D let rec aux =3D function l::ls when compare l n =3D 0 -> list | l::ls -> aux ls | [] -> list @ [n] in aux list let create list =3D let rec aux accumulator =3D function l::ls -> aux (add l accumulator) ls | [] -> accumulator in aux [] list This is terribly inefficient for big sets, but it works. It could be = made more efficient by making sure the lists are ordered, etc. Jeff ------=_NextPart_000_001F_01C50386.654FB270 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Mike,
I know of no way to do what you're = asking for.=20 However, you can always use lists as an ad hoc kind of set. Use List.mem = to=20 check membership, and some functions to add elements or create a set = while=20 looking for duplicates:
 
 
    let add n list=20 =3D
      let rec aux =3D = function
   l::ls=20 when compare l n =3D 0 -> list
 | l::ls -> aux = ls
 | []=20 -> list @ [n]
      in aux = list
 
    let create list=20 =3D
      let rec aux accumulator =3D=20 function
   l::ls -> aux (add l accumulator) = ls
 | []=20 -> accumulator
      in aux [] = list
 
This is terribly inefficient for big = sets, but it=20 works. It could be made more efficient by making sure the lists are = ordered,=20 etc.
 
Jeff
------=_NextPart_000_001F_01C50386.654FB270--