From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id E894BBC37 for ; Fri, 15 May 2009 15:49:51 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAOgPDUrZbprC/2dsb2JhbADQaIQBBQ X-IronPort-AV: E=Sophos;i="4.41,199,1241388000"; d="scan'208";a="27795929" Received: from grisu.bik-gmbh.de ([217.110.154.194]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 15 May 2009 15:49:51 +0200 Received: from [192.168.125.196] (abel.bik-gmbh.de [192.168.125.196]) by grisu.bik-gmbh.de (8.14.2/8.14.2) with ESMTP id n4FDnjxK025759; Fri, 15 May 2009 15:49:46 +0200 (CEST) (envelope-from hars@bik-gmbh.de) Message-ID: <4A0D72F9.8020409@bik-gmbh.de> Date: Fri, 15 May 2009 15:49:45 +0200 From: Florian Hars User-Agent: Thunderbird 2.0.0.21 (X11/20090409) MIME-Version: 1.0 To: Joel Christner Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Newbie list question References: <9da743ed0905131024u53a207f0s9e963be782f3f2c6@mail.gmail.com> In-Reply-To: <9da743ed0905131024u53a207f0s9e963be782f3f2c6@mail.gmail.com> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; hars:01 hars:01 bik-gmbh:01 foo:01 val:01 elt:01 vars:01 foo:01 baz:01 baz:01 val:01 vars:01 abstr:01 elt:01 recursive:01 Joel Christner schrieb: > What I'm wanting to do is create a ref list that contains a series of > strings Judging from your code, you really do not want to do this (I just sped up a program of mine by at least two orders of magnitude fixing an error like that). What you probably want to do is module S = Set.Make(String);; let s = ref S.empty;; let add_variable_ref s v = s := S.add v !s;; add_variable_ref s "foo";; add_variable_ref s "bar";; S.elements !s;; Even better if you can structure your code to get rid of the ref: # let add_variable s v = S.add v s;; val add_variable : S.t -> S.elt -> S.t = # let vars = List.fold_left add_variable S.empty ["Foo"; "Bar"; "Baz"; "Foo"; "Qux"; "Baz"];; val vars : S.t = # S.elements vars;; - : S.elt list = ["Bar"; "Baz"; "Foo"; "Qux"] Of course, this works as well, but uses more stack space as right folds are not tail recursive: # let vars' = List.fold_right S.add ["Foo"; "Bar"; "Baz"; "Foo"; "Qux"; "Baz"] S.empty;; val vars' : S.t = # S.elements vars';; - : S.elt list = ["Bar"; "Baz"; "Foo"; "Qux"] -- Florian.