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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 5FD7F7FACD for ; Mon, 29 Sep 2014 11:13:36 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of flux-caml@inside.org) identity=pra; client-ip=130.230.4.42; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="flux-caml@inside.org"; x-sender="flux-caml@inside.org"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of flux-caml@inside.org) identity=mailfrom; client-ip=130.230.4.42; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="flux-caml@inside.org"; x-sender="flux-caml@inside.org"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail.cs.tut.fi) identity=helo; client-ip=130.230.4.42; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="flux-caml@inside.org"; x-sender="postmaster@mail.cs.tut.fi"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ai0DAHshKVSC5gQql2dsb2JhbABgFoNLtmwGk3eHUgKBIQERAQEBAQEIFgdAhAQBAQMBJxNECwshJQ8BBBhEiDYIv2eGEodQgkMWhDUFi0mKVocJgWKXYWmCSgEBAQ X-IPAS-Result: Ai0DAHshKVSC5gQql2dsb2JhbABgFoNLtmwGk3eHUgKBIQERAQEBAQEIFgdAhAQBAQMBJxNECwshJQ8BBBhEiDYIv2eGEodQgkMWhDUFi0mKVocJgWKXYWmCSgEBAQ X-IronPort-AV: E=Sophos;i="5.04,619,1406584800"; d="scan'208";a="81240992" Received: from mail.cs.tut.fi ([130.230.4.42]) by mail3-smtp-sop.national.inria.fr with SMTP; 29 Sep 2014 11:13:35 +0200 Received: from amavis2.cs.tut.fi (amavis2.cs.tut.fi [130.230.4.70]) by mail.cs.tut.fi (Postfix) with ESMTP id E634F609 for ; Mon, 29 Sep 2014 12:13:33 +0300 (EEST) Received: from mail.cs.tut.fi ([130.230.4.42]) by amavis2.cs.tut.fi (amavis2.cs.tut.fi [130.230.4.70]) (amavisd-maia, port 10024) with ESMTP id 01534-43 for ; Mon, 29 Sep 2014 12:13:33 +0300 (EEST) Received: from modeemi.modeemi.fi (modeemi.modeemi.fi [130.230.72.134]) by mail.cs.tut.fi (Postfix) with SMTP id 1AA97607 for ; Mon, 29 Sep 2014 12:13:32 +0300 (EEST) Received: from coffee.modeemi.fi (coffee.modeemi.fi [130.230.72.140]) by modeemi.modeemi.fi (Postfix) with ESMTP id 9E0D63AF9D for ; Mon, 29 Sep 2014 12:13:32 +0300 (EEST) Received: by coffee.modeemi.fi (Postfix, from userid 17990) id 8EC9D2D60BF; Mon, 29 Sep 2014 12:13:32 +0300 (EEST) From: Erkki Seppala To: caml-list@yquem.inria.fr References: <87bnpzpm0l.fsf@gmail.com> <5428F0DF.9090400@ens-lyon.org> Date: Mon, 29 Sep 2014 12:13:32 +0300 In-Reply-To: <5428F0DF.9090400@ens-lyon.org> (Martin Jambon's message of "Sun, 28 Sep 2014 22:40:47 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.2 Subject: Re: [Caml-list] Why List.map does not be implemented tail-recursively? Martin Jambon writes: > Unfortunately the practice obfuscates the source code. It makes it > tricky to add or remove an operation in the chain, and overall it's an > unnecessary cognitive burden for anyone reading the code. While I do agree with this, perhaps this kind of trick could be used where it is crucial to eliminate excess reversing: type forwards = Forwards type backwards = Backwards let reverse (order1, order2, list) = (order2, order1, List.rev list) let mk list = (Forwards, Backwards, list) let forward_order = function | Forwards, _, list -> list | _, Forwards, list -> List.rev list let foo () = let xs = mk [1; 2; 3] in let xs = reverse xs in let xs = reverse xs in (* let xs = reverse xs in*) let (Forwards, _, xs) = xs in xs (* forward_order xs*) (* or: let (Forwards, _, xs) = xs in xs for compile-time assertion *) Or is it excessive?-) -- _____________________________________________________________________ / __// /__ ____ __ http://www.modeemi.fi/~flux/\ \ / /_ / // // /\ \/ / \ / /_/ /_/ \___/ /_/\_\@modeemi.fi \/