caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Raphael Proust <raphlalou@gmail.com>
To: Tie Cheng <chengtie@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] AtomMap: build a list of all the elements in a map
Date: Mon, 21 Feb 2011 14:05:19 +0100	[thread overview]
Message-ID: <AANLkTikPrnfXNRxB4L=WWKgQHeF9MCL8Vbf9amVntuTA@mail.gmail.com> (raw)
In-Reply-To: <AANLkTingFB4Jfem__Zjoq6DS-WYiYdzHUz6sYgGcb8r5@mail.gmail.com>

On Mon, Feb 21, 2011 at 1:40 PM, Tie Cheng <chengtie@gmail.com> wrote:
> Hello all,
>
> I have posted a question on Caml-beginners, but have not got response so
> far... guess maybe you could here...
>
> I have defined "type AT = A AtomMap.t". Do you know how to build a function
> "f: AT -> (atom * A) list" which returns a list of all the elements in a
> map?

It seems that OCaml 3.12 introduced the function [bindings] which has
the type and semantic you're looking for.

>
> I am trying to combine AtomMap.fold, AtomMap.Iter (in this
> manual http://cristal.inria.fr/~fpottier/alphaCaml/alphaCaml.pdf) to do
> so... But it seems that unlike List.folder_left, AtomMap.fold does not
> accept list as argument: val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b ->
> 'b, there it is not convenient to build a list progressively here...

You should be able to combine fold and iter without the list conversion step:
let fold_iter iterator folder map init =
  AtomMap.fold (fun k e accu -> iterator k e; folder k e accu) map init

(I haven't actually tried the code, but something similar should do the trick)

-- 
_______
Raphael


      parent reply	other threads:[~2011-02-21 13:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-21 12:40 Tie Cheng
2011-02-21 12:44 ` David Allsopp
2011-02-21 13:05 ` Raphael Proust [this message]

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='AANLkTikPrnfXNRxB4L=WWKgQHeF9MCL8Vbf9amVntuTA@mail.gmail.com' \
    --to=raphlalou@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=chengtie@gmail.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;
as well as URLs for NNTP newsgroup(s).