From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 0AD597EE0C for ; Thu, 29 Nov 2012 01:08:04 +0100 (CET) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of garrigue@math.nagoya-u.ac.jp) identity=pra; client-ip=133.6.130.5; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="garrigue@math.nagoya-u.ac.jp"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of garrigue@math.nagoya-u.ac.jp) identity=mailfrom; client-ip=133.6.130.5; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="garrigue@math.nagoya-u.ac.jp"; x-conformance=sidf_compatible Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mailhost.math.nagoya-u.ac.jp) identity=helo; client-ip=133.6.130.5; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="garrigue@math.nagoya-u.ac.jp"; x-sender="postmaster@mailhost.math.nagoya-u.ac.jp"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ap4EAOWmtlCFBoIF/2dsb2JhbABFwDhzgh4BAQQBJxwBNQIDCwtGITYGE4d+AwkFq0KEPwKFRQ1MiQEHi1aESWGIX4lzgV2BVYVrg1+BaoUQgn8 X-IronPort-AV: E=Sophos;i="4.84,180,1355094000"; d="scan'208";a="183706150" Received: from rabbit.math.nagoya-u.ac.jp (HELO mailhost.math.nagoya-u.ac.jp) ([133.6.130.5]) by mail1-smtp-roc.national.inria.fr with ESMTP; 29 Nov 2012 01:08:01 +0100 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id F1EA3637F; Thu, 29 Nov 2012 09:07:58 +0900 (JST) Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 831162503; Thu, 29 Nov 2012 09:07:58 +0900 (JST) DomainKey-Signature: h=Received:Subject:Mime-Version:Content-Type:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=; c=nofws; d=math.nagoya-u.ac.jp; q=; s=alpha Received: from [172.16.2.87] (unknown [211.154.201.34]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTPSA id 18B07251F; Thu, 29 Nov 2012 09:07:58 +0900 (JST) Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Content-Type: text/plain; charset=iso-8859-1 From: Jacques Garrigue In-Reply-To: Date: Thu, 29 Nov 2012 08:07:58 +0800 Cc: OCAML Content-Transfer-Encoding: quoted-printable Message-Id: References: <50B595A4.50402@wwayneb.com> <912CF782-0FD9-45D6-A6A5-2F9F50702567@first.in-berlin.de> To: Virgile Prevosto X-Mailer: Apple Mail (2.1499) Subject: Re: [Caml-list] List.fold_left vs. Hashtbl.fold On 2012/11/29, at 1:41, Virgile Prevosto wrote: > 2012/11/28 Adrien : >> Well, MoreLabels.Hashtbl has >> val fold : f:(key:'a -> data:'b -> 'c -> 'c) -> ('a, 'b) t -> init:'c= -> 'c >>=20 >=20 > Fair enough, but there's no label (say acc) to the last argument of f > (nor for the table itself), so you can't really permute the current > element and the accumulator in the argument list. Not true for fold itself: no label is equivalent to the empty label, so if you write "fold t" you are partially applying to the table. On the other hand, changing parameter order is not allowed in functions passed as argument. So reordering of arguments to f is not automatic. But at least it ensures that you do not get it wrong. Also a good reason to use labels in fold is when both remaining arguments have the same type: List.fold_left (fun l x -> if List.mem x l then l else x::l) since the accumulator and the input list have the same type, I'm always afraid of getting them wrong (ending up doing nothing). Jacques Garrigue=