From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA30296; Mon, 11 Oct 2004 10:01:30 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 KAA30000 for ; Mon, 11 Oct 2004 10:01:29 +0200 (MET DST) Received: from ext.lri.fr (ext.lri.fr [129.175.15.4]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i9B81SmL012593 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Mon, 11 Oct 2004 10:01:29 +0200 Received: from localhost (localhost [127.0.0.1]) by ext.lri.fr (Postfix) with ESMTP id E254319E703; Mon, 11 Oct 2004 10:01:28 +0200 (CEST) Received: from ext.lri.fr ([127.0.0.1]) by localhost (ext.lri.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 20186-01; Mon, 11 Oct 2004 10:01:28 +0200 (CEST) Received: from smtp.lri.fr (serveur3-5 [129.175.3.5]) by ext.lri.fr (Postfix) with ESMTP id CC9A419E6FF; Mon, 11 Oct 2004 10:01:28 +0200 (CEST) Received: from pc8-142 (pc8-142 [129.175.8.142]) by smtp.lri.fr (Postfix) with ESMTP id 8398BCEE10; Mon, 11 Oct 2004 10:01:28 +0200 (CEST) Received: from filliatr by pc8-142 with local (Exim 3.36 #1 (Debian)) id 1CGv7Y-0006Zd-00; Mon, 11 Oct 2004 10:01:28 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <16746.15832.409677.764564@gargle.gargle.HOWL> Date: Mon, 11 Oct 2004 10:01:28 +0200 To: sejourne_kevin Cc: caml-list@inria.fr Subject: Re: [Caml-list] Recursive lists In-Reply-To: <4166DC42.3090602@baretta.com> References: <41669437.3010201@yahoo.it> <4166A395.70301@yahoo.fr> <4166DC42.3090602@baretta.com> X-Mailer: VM 7.18 under Emacs 21.3.1 From: Jean-Christophe Filliatre X-Virus-Scanned: by amavisd-new at lri.fr X-Miltered: at concorde with ID 416A3DD9.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 filliatre:01 filliatre:01 lri:01 ocaml's:01 immutable:01 okasaki's:01 posts:01 ocaml's:01 lri:01 filliatr:01 filliatr:01 ipf:99 ocaml:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk sejourne_kevin wrote: > > (** Take a list and connect the end on the beginning > Copyright : Kévin ;) > *) > let cycle l = > let rl= ref l in > let rec go_fin = function > [] -> invalid_arg "cycle:[] can't be !" > | [x] as f -> Obj.set_field (Obj.repr f) 1 (Obj.repr !rl);l > | x::reste-> go_fin reste > in go_fin l > ;; > I haven't test GC issu. This shouldn't be advised, and not even posted on this list. This main property of Ocaml's lists is to be _immutable_ and therefore to implement a _persistent_ data type. This is full of very nice consequences for the programmer. (Read Okasaki's book or previous posts on this list explaining what persistence is.) But if you start mutating lists, you break this property and you endanger your code. If you need to mutate lists, why don't you use a mutable data structure, such as regular (mutable) chained lists exactly as in traditional imperative programming? (See for instance Ocaml's Queue implementation.) -- Jean-Christophe Filliâtre (http://www.lri.fr/~filliatr) PS: If you read French, I have an ocaml tutorial on my web page I recently wrote for students, where a chapter is dedicated to persistence: see http://www.lri.fr/~filliatr/publis/ipf.ps.gz This is a rather modest contribution (compared to Richard Jones's tutorial for instance) and it does not even describe all features of ocaml, but at least it explains why you shouldn't mutate lists. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners