From: "David Allsopp" <dra-news@metastack.com>
To: "'Tom Wilkie'" <tom@acunu.com>, <caml-list@yquem.inria.fr>
Subject: RE: [Caml-list] Queue.fold give wrong order?
Date: Tue, 19 Jan 2010 15:22:28 -0000 [thread overview]
Message-ID: <00d401ca991b$36c5f470$a451dd50$@romulus.metastack.com> (raw)
In-Reply-To: <F0AD2B48-279E-4121-8242-F56F2EE6642F@acunu.com>
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 = <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 = ()
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
next prev parent reply other threads:[~2010-01-19 15:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-19 15:10 Tom Wilkie
2010-01-19 15:22 ` David Allsopp [this message]
2010-01-19 15:53 [Caml-list] " Bruno Verlyck, Bruno.Verlyck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='00d401ca991b$36c5f470$a451dd50$@romulus.metastack.com' \
--to=dra-news@metastack.com \
--cc=caml-list@yquem.inria.fr \
--cc=tom@acunu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox