Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Re: [Caml-list] Queue.fold give wrong order?
@ 2010-01-19 15:53 Bruno Verlyck, Bruno.Verlyck
  0 siblings, 0 replies; 2+ messages in thread
From: Bruno Verlyck, Bruno.Verlyck @ 2010-01-19 15:53 UTC (permalink / raw)
  To: Tom Wilkie; +Cc: caml-list

Hi,

From: Tom Wilkie <tom@acunu.com>
Date: Tue, 19 Jan 2010 15:10:43 +0000
> 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?
It's already the case.

> # Queue.fold (fun acc a -> a::acc) [] q;;
> - : int list = [3; 2; 1]
Your (fun acc a -> a::acc) is first called with args [] and 1, and
yields a next value for accu of [1]; and so on.

HTH,
Bruno.


^ permalink raw reply	[flat|nested] 2+ messages in thread
* Queue.fold give wrong order?
@ 2010-01-19 15:10 Tom Wilkie
  2010-01-19 15:22 ` [Caml-list] " David Allsopp
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Wilkie @ 2010-01-19 15:10 UTC (permalink / raw)
  To: caml-list; +Cc: Tom Wilkie

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 = <abstr>
# 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 = ()


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-01-19 15:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-19 15:53 [Caml-list] Queue.fold give wrong order? Bruno Verlyck, Bruno.Verlyck
  -- strict thread matches above, loose matches on Subject: below --
2010-01-19 15:10 Tom Wilkie
2010-01-19 15:22 ` [Caml-list] " David Allsopp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox