From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p1LD5XJY010207 for ; Mon, 21 Feb 2011 14:05:33 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As4BAEPyYU1KfVMskGdsb2JhbACEH6IFCBUBAQEBCQkMBxEEIJ9+iVw8ghyEKi+IWgEBAwWBIoNBdgSME4ZLgX06 X-IronPort-AV: E=Sophos;i="4.62,200,1297033200"; d="scan'208";a="76296306" Received: from mail-gw0-f44.google.com ([74.125.83.44]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 21 Feb 2011 14:05:20 +0100 Received: by gwaa18 with SMTP id a18so376145gwa.3 for ; Mon, 21 Feb 2011 05:05:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=5b8MBvoUM5MfxXYfNPGQ/1ILgAzOrcnd9NTDroQI1mA=; b=Qt6kQoI7gkvfnDrJ4QjgdVMG3xDexa0SdZg23vhnxQ1XBBjIVSqOMOas92U4FrUpAu ltyEhmYM4CjiTBF+1fN6IRBOzwxa2GQH2u1UBOjIiLQrW+i+/dp8jn4eLtni/foXcctd GMBXbn8o458qQ2ot9oSPFi6GswEcKNvU5+EEw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=D1QUi8c9LOorPvy+pn9Vy3LE/sTNDVIIGI3JWWfM0KPmCIXZ04+1siZxttEApsUGSR RDgKF0mrVua0BCoY8OhLJhfcCHGUMkNUyIweVaFlsqrGRUziR/ojsw68+TqHcagPByau Z/x5aBp79wEx7E6GKlQ62gNcDWYBHH8EubD+Y= MIME-Version: 1.0 Received: by 10.151.51.20 with SMTP id d20mr1687234ybk.320.1298293519095; Mon, 21 Feb 2011 05:05:19 -0800 (PST) Received: by 10.151.110.14 with HTTP; Mon, 21 Feb 2011 05:05:19 -0800 (PST) In-Reply-To: References: Date: Mon, 21 Feb 2011 14:05:19 +0100 Message-ID: From: Raphael Proust To: Tie Cheng Cc: caml-list@yquem.inria.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p1LD5XJY010207 Subject: Re: [Caml-list] AtomMap: build a list of all the elements in a map On Mon, Feb 21, 2011 at 1:40 PM, Tie Cheng 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