From: Francois Berenger <berenger@riken.jp>
To: caml-list@inria.fr
Subject: Re: [Caml-list] short-circuit in Real World Ocaml ch 3 deserves a comment
Date: Mon, 25 Nov 2013 10:36:11 +0900 [thread overview]
Message-ID: <5292A98B.9010202@riken.jp> (raw)
In-Reply-To: <1384873538.80445.YahooMailNeo@web160506.mail.bf1.yahoo.com>
On 11/20/2013 12:05 AM, Jean Saint-Remy wrote:
> [...]
> The example code using pattern matching appears to be a "let rec"
> short-circuit which I believe deserves a comment in the book. It appears
> to be puzzling, we are binding a "zero" to the head of the list in order
> to drop it? I think it is a fine example of OCaml that should be
> encouraged, not just an isolated case.
>
> let rec drop_zero ls = match ls with
> | [] -> []
> | 0 :: tl -> drop_zero tl
> | hd :: tl -> hd :: drop_zero tl
> ;;
Are we really speaking of some "real world" OCaml?
This code is not tail recursive and can be replaced
by a one liner using List.filter from the standard library.
prev parent reply other threads:[~2013-11-25 1:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-19 15:05 Jean Saint-Remy
2013-11-19 22:11 ` Nicolas Braud-Santoni
2013-11-25 1:36 ` Francois Berenger [this message]
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=5292A98B.9010202@riken.jp \
--to=berenger@riken.jp \
--cc=caml-list@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