caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nicolas Braud-Santoni <nicolas@braud-santoni.eu>
To: caml-list@inria.fr
Subject: Re: [Caml-list] short-circuit in Real World Ocaml ch 3 deserves a comment
Date: Tue, 19 Nov 2013 23:11:15 +0100	[thread overview]
Message-ID: <528BE203.7030108@braud-santoni.eu> (raw)
In-Reply-To: <1384873538.80445.YahooMailNeo@web160506.mail.bf1.yahoo.com>

[-- Attachment #1: Type: text/plain, Size: 890 bytes --]

On 19/11/2013 16:05, 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
> ;;

Hi,

It isn't a « short circuit » : the list is pattern matched, and if it
matches `0 :: tl`, then the result is `drop_zero tl`.
The head of the list (0) is effectively dropped by not including it on
the right hand side.

And, as far as I know, it is rather idiomatic to use pattern matching in
the way (when matching over suitable datatypes).


Regards,
Nicolas


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2013-11-19 22:11 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 [this message]
2013-11-25  1:36 ` Francois Berenger

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=528BE203.7030108@braud-santoni.eu \
    --to=nicolas@braud-santoni.eu \
    --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;
as well as URLs for NNTP newsgroup(s).