caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean Saint-Remy <jeansaintremy@yahoo.com>
To: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: [Caml-list] short-circuit in Real World Ocaml ch 3 deserves a comment
Date: Tue, 19 Nov 2013 07:05:38 -0800 (PST)	[thread overview]
Message-ID: <1384873538.80445.YahooMailNeo@web160506.mail.bf1.yahoo.com> (raw)

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

Hi,

I found a missing "does not change" sentence fragment in the third section on Lists and Patterns


"Each:: essentially adds a new block to the proceding picture. Such a block contains two things: a reference to the data in that list element, and a reference to the remainder of the list. This is why :: can extend a list without modifying it; extension allocates a new list element but {here} change any of the existing ones, as you can see: "


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 

;;

With kind regards,

Jean

[-- Attachment #2: Type: text/html, Size: 1408 bytes --]

             reply	other threads:[~2013-11-19 15:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-19 15:05 Jean Saint-Remy [this message]
2013-11-19 22:11 ` Nicolas Braud-Santoni
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=1384873538.80445.YahooMailNeo@web160506.mail.bf1.yahoo.com \
    --to=jeansaintremy@yahoo.com \
    --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).