From: Erkki Seppala <flux-caml@inside.org>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Why List.map does not be implemented tail-recursively?
Date: Mon, 29 Sep 2014 12:13:32 +0300 [thread overview]
Message-ID: <m49fvfadc1v.fsf@coffee.modeemi.fi> (raw)
In-Reply-To: <5428F0DF.9090400@ens-lyon.org> (Martin Jambon's message of "Sun, 28 Sep 2014 22:40:47 -0700")
Martin Jambon <martin.jambon@ens-lyon.org> 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 \/
next prev parent reply other threads:[~2014-09-29 9:13 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2014-09-29 9:15 ` Erkki Seppala
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
2014-09-29 21:00 ` Gabriel Scherer
2014-10-02 10:09 ` 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
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=m49fvfadc1v.fsf@coffee.modeemi.fi \
--to=flux-caml@inside.org \
--cc=caml-list@yquem.inria.fr \
/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