caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Virgile Prevosto <virgile.prevosto@m4x.org>
Cc: OCAML <caml-list@inria.fr>
Subject: Re: [Caml-list] List.fold_left vs. Hashtbl.fold
Date: Thu, 29 Nov 2012 08:07:58 +0800	[thread overview]
Message-ID: <DD9F7E17-3038-459A-AC87-B7302FF15CEB@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CA+yPOVi2tH038PQBMQYLN9_muhuD1ibcXGgAQ6NL2WLYqz6HaQ@mail.gmail.com>

On 2012/11/29, at 1:41, Virgile Prevosto <virgile.prevosto@m4x.org> wrote:

> 2012/11/28 Adrien <camaradetux@gmail.com>:
>> Well, MoreLabels.Hashtbl has
>>  val  fold  : f:(key:'a -> data:'b -> 'c -> 'c) -> ('a, 'b) t -> init:'c -> 'c
>> 
> 
> 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

  reply	other threads:[~2012-11-29  0:08 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-28  4:40 William Smith
2012-11-28 16:17 ` Lukasz Stafiniak
2012-11-28 16:25   ` Malcolm Matalka
2012-11-28 16:21 ` David House
2012-11-29  1:06   ` Francois Berenger
2012-11-28 16:42 ` Oliver Bandel
2012-11-28 17:11   ` Adrien
2012-11-28 17:41     ` Virgile Prevosto
2012-11-29  0:07       ` Jacques Garrigue [this message]
     [not found] ` <CAPFanBG04BiwJuPkV80__Ondmg1N8OEg4DokiXqDReg3ycNBdA@mail.gmail.com>
2012-11-28 17:25   ` Gabriel Scherer
2012-11-28 17:37     ` Lukasz Stafiniak
2012-11-30  3:06 William Smith
2012-11-30  9:53 ` Gabriel Scherer
2012-11-30 10:06   ` Stefano Zacchiroli
2012-11-30 16:00     ` Gabriel Scherer
2012-11-30 16:48       ` Daniel Bünzli
2012-11-30 11:34   ` Daniel Bünzli

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=DD9F7E17-3038-459A-AC87-B7302FF15CEB@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=virgile.prevosto@m4x.org \
    /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).