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 IAA08467; Tue, 12 Oct 2004 08:12:58 +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 IAA08331 for ; Tue, 12 Oct 2004 08:12:57 +0200 (MET DST) Received: from smtp005.mail.ukl.yahoo.com (smtp005.mail.ukl.yahoo.com [217.12.11.36]) by concorde.inria.fr (8.13.0/8.13.0) with SMTP id i9C6Cv3R014578 for ; Tue, 12 Oct 2004 08:12:57 +0200 Received: from unknown (HELO yahoo.fr) (sejourne?kevin@82.121.19.110 with plain) by smtp005.mail.ukl.yahoo.com with SMTP; 12 Oct 2004 06:12:56 -0000 Message-ID: <416B7710.5020901@yahoo.fr> Date: Tue, 12 Oct 2004 08:17:52 +0200 From: sejourne_kevin User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040528 Debian/1.6-7 X-Accept-Language: fr-fr MIME-Version: 1.0 To: Jean-Christophe Filliatre CC: caml-list@inria.fr Subject: Re: [Caml-list] Recursive lists References: <41669437.3010201@yahoo.it> <4166A395.70301@yahoo.fr> <4166DC42.3090602@baretta.com> <16746.15832.409677.764564@gargle.gargle.HOWL> In-Reply-To: <16746.15832.409677.764564@gargle.gargle.HOWL> Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 416B75E9.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 ocaml's:01 immutable:01 okasaki's:01 posts:01 ocaml's:01 baretta:01 immutable:01 ocaml:01 mutable:01 mutable:01 alex:01 rec:01 simpler:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Jean-Christophe Filliatre wrote: > 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.) > With the modification of Alex Baretta this function can be be view as returning a _new_ list. So the list is immutable. When I right this function it was for _fun_. So if Obj don't exist I use a C primitive. I can have a cycle using '[]' and '::' syntaxe this a great thing. I think a improvement for Ocaml3.09 that allow let ([]) = ... and (::) = ... is a better way and simpler. ------------------- 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