From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 3F4FCBBAF for ; Tue, 19 Jan 2010 16:22:39 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsBAOZcVUtRZ90xkWdsb2JhbACbfwEBAQEJCwoHEwO7OoQzBA X-IronPort-AV: E=Sophos;i="4.49,303,1262559600"; d="scan'208";a="45204026" Received: from mtaout03-winn.ispmail.ntl.com ([81.103.221.49]) by mail1-smtp-roc.national.inria.fr with ESMTP; 19 Jan 2010 16:22:38 +0100 Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20100119152238.JWZB17277.mtaout03-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com>; Tue, 19 Jan 2010 15:22:38 +0000 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout02-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20100119152238.IVJA21638.aamtaout02-winn.ispmail.ntl.com@romulus.metastack.com>; Tue, 19 Jan 2010 15:22:38 +0000 Received: from Tenor ([172.16.0.8]) (authenticated bits=0) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id o0JFMYbS000636 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Tue, 19 Jan 2010 15:22:35 GMT From: "David Allsopp" To: "'Tom Wilkie'" , References: In-Reply-To: Subject: RE: [Caml-list] Queue.fold give wrong order? Date: Tue, 19 Jan 2010 15:22:28 -0000 Message-ID: <00d401ca991b$36c5f470$a451dd50$@romulus.metastack.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQGzaYAxBMkcoa4UO9HNLumDr4bl7gFwF/rP Content-Language: en-gb Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 81.102.132.77 X-Cloudmark-Analysis: v=1.1 cv=1ggfb5FlKZQUfF3vzm9UBYZ2uTfLsbs/8dSljwg5+mE= c=1 sm=0 a=h7ggTe-2GcgA:10 a=zcjvlnFAX9cIBCpu1EIA:9 a=gdO0gd9ewSfp6INDyfgYcwREtAQA:4 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 X-Spam: no; 0.00; inserting:01 ocaml:01 val:01 abstr:01 iter:01 endline:01 iter:01 endline:01 beginners':01 wrote:01 caml-list:01 int:01 int:01 behaviour:01 caml:02 Tom Wilkie wrote: > Dear all > > Is Queue.fold going over items in the wrong order? It says "equivalent > to List.fold_left" but I would expect the behaviour to be, when > inserting items 1, then 2, then 3 a fold would be given items in that > order? > > Is there a good reason for this? Could be have a rev_fold for the > opposite order please? > > Thanks > > Tom > > # ocaml > Objective Caml version 3.10.2 > > # open Queue;; > # let q = Queue.create ();; > val q : '_a Queue.t = > # Queue.add 1 q;; > - : unit = () > # Queue.add 2 q;; > - : unit = () > # Queue.add 3 q;; > - : unit = () > # Queue.fold (fun acc a -> a::acc) [] q;; > - : int list = [3; 2; 1] > # Queue.iter (fun a -> print_endline (string_of_int a)) q;; > 1 > 2 > 3 > - : unit = () List.fold_left (fun acc a -> a::acc) [] [1; 2; 3];; List.iter (fun a -> print_endline (string_of_int a)) [1; 2; 3];; If that still puzzles you then please, with respect, re-post to the beginners' list. David