From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 2711CBBAF for ; Mon, 28 Jun 2010 04:34:05 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuoEADKnJ0xQW+UMgWdsb2JhbACSfYwvFQEBFiIivjeFJAQ X-IronPort-AV: E=Sophos;i="4.53,494,1272837600"; d="scan'208";a="65451667" Received: from lo.gmane.org ([80.91.229.12]) by mail4-smtp-sop.national.inria.fr with ESMTP; 28 Jun 2010 04:34:04 +0200 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OT4Ac-0006gr-P6 for caml-list@inria.fr; Mon, 28 Jun 2010 04:34:02 +0200 Received: from bas3-toronto02-1279545582.dsl.bell.ca ([76.68.80.238]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 28 Jun 2010 04:34:02 +0200 Received: from michael by bas3-toronto02-1279545582.dsl.bell.ca with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 28 Jun 2010 04:34:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Michael Ekstrand Subject: Re: Symbol type Date: Sun, 27 Jun 2010 22:33:54 -0400 Message-ID: References: <20100628021543.GA14360@malaquias.DHCP-GERAL> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: bas3-toronto02-1279545582.dsl.bell.ca User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Lightning/1.0b1 Thunderbird/3.0.4 In-Reply-To: <20100628021543.GA14360@malaquias.DHCP-GERAL> X-Enigmail-Version: 1.0.1 X-Spam: no; 0.00; romildo:01 malaquias:01 ocaml:01 compiler:01 integers:01 integers:01 intern:01 foo:01 atoms:98 interns:98 interns:98 prolog:01 wrote:01 strings:01 lisp:02 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