Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Queue.fold give wrong order?

1 view
Skip to first unread message

Tom Wilkie

unread,
Jan 19, 2010, 10:10:55 AM1/19/10
to caml...@yquem.inria.fr
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 = ()

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

David Allsopp

unread,
Jan 19, 2010, 10:22:47 AM1/19/10
to Tom Wilkie, caml...@yquem.inria.fr

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

0 new messages