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 KAA07971; Tue, 24 Sep 2002 10:36:20 +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 KAA07599 for ; Tue, 24 Sep 2002 10:36:19 +0200 (MET DST) Received: from athlon.baretta.com (host121-68.pool80116.interbusiness.it [80.116.68.121]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g8O8aI503241 for ; Tue, 24 Sep 2002 10:36:18 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 26F9627399; Tue, 24 Sep 2002 10:45:50 +0200 (CEST) Message-ID: <3D90263D.2010706@baretta.com> Date: Tue, 24 Sep 2002 10:45:49 +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: =?ISO-8859-1?Q?Micha=EBl_Gr=FCnewald?= , Ocaml , Pixel Subject: Re: [Caml-list] Re: Wasn't O'Caml a functional language? References: <3D8CF6F8.2050904@baretta.com> <15756.65084.40025.869484@spike.artisan.com> <3D8D050F.9000108@baretta.com> <871y7m1wlv.fsf@ketanu.dyndns.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Michaël Grünewald wrote: > Alessandro Baretta writes: > >>Anyway, my main claim, although misdirected, in not entirely >>faulty. Queue.transfer can be thought of as analogous to >>List.append. When I write let list = list1 @ list2 I do not expect >>side-effects on list1 or list2. > > > Then you maybe should use Lists, why, if queues have the same behavior than > lists, give them a different name ? They don't have the same behavior, and are not supposed to have the same behaviour. let l = [] in let l = e1 :: l in let l = e2 :: l in let l = e3 :: l in List.iter f l is equivalent to f e3; f e2; fe1 which is not what I need. On the other hand, let q = Queue.create () in let _ = Queue.add e1 q in let _ = Queue.add e2 q in let _ = Queue.add e3 q in Queue.iter f q is equivalent to f e1; f e2; f e3 which is correct with respect to what I need. This is the reason for using Queues. I somehow expected this to be the only difference with respect to Lists, and did not suspect that some of the functions of the Queue module (other than the obvious add and take) had side-effects. I realize that "transfer" is a significantly different name than "append", and I should have known better than to use it without expecting side-effects, but, anyway, I was stumbled on this function. And, believe me, it took me quite a while to figure out in Ocamldebug/Epeire why in the world my program was doing what it was. So let me say, "Long live functional iterators which have no side-effects! Down with explicit handling of aliasing! " [ ... feel free to add here whatever political slogans you like best ;) ] BTW, picking up on Pixel's comment, I don't really know whether Queues are any more efficient than lists-used-as-FIFO, although I would expect them to be. I am mostly interested in the conciseness of the API. Queue.iter f q is much more elegant and readable than the equivalent List.iter f (List.rev l) Of course, performance is also important, but the software I'm writing will have its bottleneck in IO anyway, so no there is no significant advantage to be had by optimising the algorithms, other than to increase the fraction of CPU idle time, which is already pretty high. Of course, in other contexts, performace would matter a lot more. Cheers, 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