Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Yaron Minsky <yminsky@janestreet.com>
To: Pierre Chambart <pierre.chambart@laposte.net>
Cc: Goswin von Brederlow <goswin-v-b@web.de>,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Why List.map does not be implemented tail-recursively?
Date: Mon, 29 Sep 2014 11:44:34 -0400	[thread overview]
Message-ID: <CACLX4jTAbDE_7XUQR+j_AWoD1N1zn5D5N=+h7=Unzz-09FfYjA@mail.gmail.com> (raw)
In-Reply-To: <54296663.8080902@laposte.net>

Agreed.  To be clear, there's a "hack" in Core_kernel's List module
that does more or less what is described, but the gluing together
isn't hacky, i.e., uses no Obj.magic and no mutation.  It's both fast
for short lists and doesn't blow the stack for long lists.

y

On Mon, Sep 29, 2014 at 10:02 AM, Pierre Chambart
<pierre.chambart@laposte.net> wrote:
> On 29/09/2014 14:08, Goswin von Brederlow wrote:
>> And I'll will do the same, reply anyway.
>>
>> You can't write List.map tail recursive unless:
>>
>> 1) You use List.rev (List.rev_map fn list).
>>
>> or
>>
>> 2) Use hacks to create a mutable list so you can grow it head to tail
>> instead of tail to head.
>>
>> The fastest code seems to be when you do List.map recursively up to
>> some limit (say 1000 items) and return the remainder. Repeat and glue
>> the lists together into one large list using hacks.
>>
>> MfG
>>       Mrvn
>>
> Please, don't do that hack ! The compiler assumes immutable data are not
> mutated and optimise knowing that.
> --
> Pierre
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

  reply	other threads:[~2014-09-29 15:44 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-28 19:31 Shuai Wang
2014-09-28 19:36 ` Gabriel Scherer
2014-09-28 19:45 ` Anthony Tavener
2014-09-29 12:08   ` Goswin von Brederlow
2014-09-29 14:02     ` Pierre Chambart
2014-09-29 15:44       ` Yaron Minsky [this message]
2014-09-29 21:00       ` Gabriel Scherer
2014-09-30  8:46         ` [Caml-list] Why List.map does not be implemented oleg
2014-09-30  9:07           ` Gabriel Scherer
2014-10-01 10:29             ` oleg
2014-10-01 12:00               ` Gerd Stolpmann
2014-10-29 10:11               ` Gabriel Scherer
2014-10-02 10:09         ` [Caml-list] Why List.map does not be implemented tail-recursively? Stephen Dolan
2015-06-01 12:02           ` Jon Harrop
2015-06-02 12:04             ` Stephen Dolan
2015-06-05 10:21               ` Goswin von Brederlow
2014-09-30  6:29       ` Goswin von Brederlow
  -- strict thread matches above, loose matches on Subject: below --
2014-09-28 19:28 Shuai Wang
2014-09-28 19:45 ` Malcolm Matalka
2014-09-28 20:26   ` Yaron Minsky
2014-09-29  2:31     ` Shuai Wang
2014-09-29  4:09       ` Anthony Tavener
2014-09-29  5:40         ` Martin Jambon
2014-09-29  9:13           ` Erkki Seppala
2014-09-29  9:15             ` Erkki Seppala

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='CACLX4jTAbDE_7XUQR+j_AWoD1N1zn5D5N=+h7=Unzz-09FfYjA@mail.gmail.com' \
    --to=yminsky@janestreet.com \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    --cc=pierre.chambart@laposte.net \
    /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