caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Jeff Shaw" <shawjef3@msu.edu>
To: <hamburg@fas.harvard.edu>
Cc: <caml-list@inria.fr>
Subject: Re: 'a Set?
Date: Wed, 26 Jan 2005 09:07:00 -0500	[thread overview]
Message-ID: <002201c503b0$5fb65740$6600a8c0@gft> (raw)

[-- Attachment #1: Type: text/plain, Size: 677 bytes --]

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 =
      let rec aux = function
   l::ls when compare l n = 0 -> list
 | l::ls -> aux ls
 | [] -> list @ [n]
      in aux list

    let create list =
      let rec aux accumulator = 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

[-- Attachment #2: Type: text/html, Size: 1629 bytes --]

             reply	other threads:[~2005-01-26 14:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-26 14:07 Jeff Shaw [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-01-25 23:54 Mike Hamburg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='002201c503b0$5fb65740$6600a8c0@gft' \
    --to=shawjef3@msu.edu \
    --cc=caml-list@inria.fr \
    --cc=hamburg@fas.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).