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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 7F52C7FACD for ; Mon, 29 Sep 2014 16:02:45 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of pierre.chambart@laposte.net) identity=pra; client-ip=193.253.67.227; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="pierre.chambart@laposte.net"; x-sender="pierre.chambart@laposte.net"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of pierre.chambart@laposte.net designates 193.253.67.227 as permitted sender) identity=mailfrom; client-ip=193.253.67.227; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="pierre.chambart@laposte.net"; x-sender="pierre.chambart@laposte.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@smtpout.laposte.net) identity=helo; client-ip=193.253.67.227; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="pierre.chambart@laposte.net"; x-sender="postmaster@smtpout.laposte.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArYBACVmKVTB/UPjm2dsb2JhbABg0nyDIQKBJAERAQEBAQEGCwsJFCyEBAEBBHgRCxgJFg8JAwIBAgFFBgEMCAKIJQEYt0cQh2cBF49HXoRLAQSSapIQkXCBcYFDAQEB X-IPAS-Result: ArYBACVmKVTB/UPjm2dsb2JhbABg0nyDIQKBJAERAQEBAQEGCwsJFCyEBAEBBHgRCxgJFg8JAwIBAgFFBgEMCAKIJQEYt0cQh2cBF49HXoRLAQSSapIQkXCBcYFDAQEB X-IronPort-AV: E=Sophos;i="5.04,620,1406584800"; d="scan'208";a="98437512" Received: from smtpout2.laposte.net (HELO smtpout.laposte.net) ([193.253.67.227]) by mail2-smtp-roc.national.inria.fr with ESMTP; 29 Sep 2014 16:02:14 +0200 Received: from [192.168.0.132] ([81.64.137.19]) by mwinf8503-out with ME id x22B1o00M0RHR010322Blp; Mon, 29 Sep 2014 16:02:13 +0200 Message-ID: <54296663.8080902@laposte.net> Date: Mon, 29 Sep 2014 16:02:11 +0200 From: Pierre Chambart User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.0 MIME-Version: 1.0 To: Goswin von Brederlow , caml-list@inria.fr References: <20140929120817.GB20628@frosties> In-Reply-To: <20140929120817.GB20628@frosties> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Why List.map does not be implemented tail-recursively? 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