From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p1LCrgix009300 for ; Mon, 21 Feb 2011 13:53:42 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuYBAPvuYU1RZ90vkWdsb2JhbACEH6ExXBUBAQEBCQsKBxEDIalckBCBJ4NBdgSMEw X-IronPort-AV: E=Sophos;i="4.62,200,1297033200"; d="scan'208";a="100331980" Received: from mtaout01-winn.ispmail.ntl.com ([81.103.221.47]) by mail1-smtp-roc.national.inria.fr with ESMTP; 21 Feb 2011 13:53:37 +0100 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20110221125337.KTUM26766.mtaout01-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com>; Mon, 21 Feb 2011 12:53:37 +0000 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout01-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20110221125336.GIZK20122.aamtaout01-winn.ispmail.ntl.com@romulus.metastack.com>; Mon, 21 Feb 2011 12:53:36 +0000 Received: from remus.metastack.local ([172.16.0.1]) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id p1LCrURX018729 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Mon, 21 Feb 2011 12:53:30 GMT Received: from Remus.metastack.local ([fe80::547c:3c42:e1da:eda2]) by Remus.metastack.local ([fe80::547c:3c42:e1da:eda2%11]) with mapi; Mon, 21 Feb 2011 12:48:52 +0000 From: David Allsopp To: "'Tie Cheng'" , "'caml-list@yquem.inria.fr'" Thread-Topic: [Caml-list] AtomMap: build a list of all the elements in a map Thread-Index: AQHL0cPyES9aMKaCEUKsnxE7cLJVYZQL5W8A Date: Mon, 21 Feb 2011 12:44:31 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 81.102.132.77 X-Cloudmark-Analysis: v=1.1 cv=JvdXmxIgLJv2/GthKqHpGJEEHukvLcvELVXUanXFreg= c=1 sm=0 a=2n0YD5bBMfMA:10 a=IkcTkHD0fZMA:10 a=xqWC_Br6kY4A:10 a=ZOzjf2MOAAAA:8 a=xWX5Lo3dh-FNlf-TRm4A:9 a=TkMOwkg-jnEF7nhBxKsbiNErjecA:4 a=QEXdDO2ut3YA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by walapai.inria.fr id p1LCrgix009300 Subject: RE: [Caml-list] AtomMap: build a list of all the elements in a map Tie Cheng wrote: > 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? > 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... I don't see how that function signature differs from what you expect so sorry if that's because I don't know anything about alphaCaml! What's wrong with: fold (fun key value acc -> (key, value)::acc)) atomMap [] The signature for [fold] is simply like the signature for List.fold_right rather than List.fold_left. David