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 AAA14225; Sun, 22 Sep 2002 00:37:55 +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 AAA14611 for ; Sun, 22 Sep 2002 00:37:54 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (r-mi214-6a121.tin.it [62.211.4.121]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g8LMbr503411 for ; Sun, 22 Sep 2002 00:37:53 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 29AA82724C for ; Sun, 22 Sep 2002 00:47:20 +0200 (CEST) Message-ID: <3D8CF6F8.2050904@baretta.com> Date: Sun, 22 Sep 2002 00:47:20 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020826 X-Accept-Language: it, en MIME-Version: 1.0 To: Ocaml Subject: [Caml-list] Wasn't O'Caml a functional language? Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk First of all, allow me to RTFM myself before anybody else does. I just spent the last hour or so tracking down a bug caused by the "procedural-style" side-effect in Queue.iter: the queue is actually emptied by that function. Now, if O'Caml is a functional language, and Queue.iter is a functional iterator, why is there a need for that very counterintuitive side-effect? If I use List.iter on a list, I do not expect it to flush my list of all it's contents. The same with a Hashtbl.iter, and in general with all functional iterators, which are the very heart of the standard library. In my opinion, "The Right Way (TM)" to use datastructures in O'Caml and in functional languages in general is to build them, iterate non-destructively over them as many times as necessary, and finally let the GC reclaim them when they are no longer accessible from the live scope. What makes this approach much simpler to handle, much more intuitive to understand and less intricate to debug, is that data structure aliasing does not have to be explicitly taken into account. On the other hand, if one uses iterators with side-effects and the data structures are aliased--as was my case in my application, until I figured out what was going wrong--all sorts of weird non-local bugs can appear, and tracking them down can take quite a few runs of ocamldebug. Concluding, let me "break a spear"--as we say in Italian--in favor of a purely functional standard library, where such datastructures as Queue.t's and the like can be freely aliased without a second thought. Cheers, and back to work... Alex ------------------- 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