caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michael Ekstrand <michael@elehack.net>
To: caml-list@inria.fr
Subject: Re: Symbol type
Date: Sun, 27 Jun 2010 22:33:54 -0400	[thread overview]
Message-ID: <i091mj$e90$1@dough.gmane.org> (raw)
In-Reply-To: <20100628021543.GA14360@malaquias.DHCP-GERAL>

On 06/27/2010 10:15 PM, José Romildo Malaquias wrote:
> Is there a symbol type in OCaml, with a constant time comparison
> function? Something like symbols from Scheme and LISP or atoms from
> Prolog. Useful in compiler construction.

Not directly.  As I see it, you have two decent options:

- Use/write a symbol table which "interns" symbols to integers.  The
resulting integers can be compared.
- Use/write a symbol table which interns symbols to unique string
instances, so SymTbl.intern "foo" returns the existing string object if
one already exists, and the string object passed in if it's never been
seen before.  The resulting strings can be compared with == rather than
= in constant time.

Either of these options would be fairly similar to how symbols work
under the hood in a Lisp implementation, I believe.

- Michael


  reply	other threads:[~2010-06-28  2:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-28  2:15 José Romildo Malaquias
2010-06-28  2:33 ` Michael Ekstrand [this message]
2010-06-28 13:37   ` [Caml-list] " Nicholas Kidd
2010-06-28  4:56 ` [Caml-list] " bluestorm

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='i091mj$e90$1@dough.gmane.org' \
    --to=michael@elehack.net \
    --cc=caml-list@inria.fr \
    /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).