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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 728997EE25 for ; Tue, 19 Nov 2013 23:11:28 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of nicolas.braudsantoni@gmail.com) identity=pra; client-ip=74.125.83.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="nicolas.braudsantoni@gmail.com"; x-sender="nicolas.braudsantoni@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of nicolas.braudsantoni@gmail.com designates 74.125.83.41 as permitted sender) identity=mailfrom; client-ip=74.125.83.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="nicolas.braudsantoni@gmail.com"; x-sender="nicolas.braudsantoni@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ee0-f41.google.com) identity=helo; client-ip=74.125.83.41; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="nicolas.braudsantoni@gmail.com"; x-sender="postmaster@mail-ee0-f41.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkIDAIbhi1JKfVMplGdsb2JhbABZxHMWDgEBAQEHCwsJEiqCJQEBBScZATcCAwwBBQUYCRYPCQMCAQIBIgEFARwTCAEBh2sDDwQBoi+PYIRKJw2IawEFDI9ohBwDkDCBMYJPiiGJYkGBZIJw X-IPAS-Result: AkIDAIbhi1JKfVMplGdsb2JhbABZxHMWDgEBAQEHCwsJEiqCJQEBBScZATcCAwwBBQUYCRYPCQMCAQIBIgEFARwTCAEBh2sDDwQBoi+PYIRKJw2IawEFDI9ohBwDkDCBMYJPiiGJYkGBZIJw X-IronPort-AV: E=Sophos;i="4.93,732,1378850400"; d="asc'?scan'208";a="43916144" Received: from mail-ee0-f41.google.com ([74.125.83.41]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 19 Nov 2013 23:11:28 +0100 Received: by mail-ee0-f41.google.com with SMTP id t10so2361606eei.28 for ; Tue, 19 Nov 2013 14:11:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type; bh=KuR588G/k/cPItYdawYOnL21pbZsyj7BOY4e1nFeTnY=; b=0g9ZvUidmNl8iSaC/rhNYPjS+30b083m7ou4kAL4sUPm0/tF8aJizdt99593lKg0ou R3ensjB6Yub5OG375y5PFDBlqJ6RGn/1MRkYHznebnHx7X1BGXrTf8ciby/mH28mcDKw 9z+PfFORkrBEEP+e94CvuSelC4ETDWTxtuqdBWoem5iojljU4FRNBPSVrRL17f8qZ0aX T5XcEN6+/YexSIQ4RzhXMiR7a67T+4MH7InOyIUbpN4PUJjXxlY5Bwo4/+T/1Ba0T0lV Y2GwqIxV5iQg1L4KDuveLuJJtdbavq19kR/nbC9myOJan0Lv6pEeLbFNxs7re4xHFLLc d7Pw== X-Received: by 10.14.1.130 with SMTP id 2mr32021962eed.24.1384899086843; Tue, 19 Nov 2013 14:11:26 -0800 (PST) Received: from [193.170.224.192] (m-192.vc-graz.ac.at. [193.170.224.192]) by mx.google.com with ESMTPSA id x4sm53046508eef.1.2013.11.19.14.11.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Nov 2013 14:11:25 -0800 (PST) Sender: Nicolas Braud-Santoni Message-ID: <528BE203.7030108@braud-santoni.eu> Date: Tue, 19 Nov 2013 23:11:15 +0100 From: Nicolas Braud-Santoni User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: caml-list@inria.fr References: <1384873538.80445.YahooMailNeo@web160506.mail.bf1.yahoo.com> In-Reply-To: <1384873538.80445.YahooMailNeo@web160506.mail.bf1.yahoo.com> X-Enigmail-Version: 1.6 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="CEiMcfPkHBV12cs9QKWxuCUaPRGO712HP" X-Validation-by: nicolas@braud-santoni.eu Subject: Re: [Caml-list] short-circuit in Real World Ocaml ch 3 deserves a comment This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --CEiMcfPkHBV12cs9QKWxuCUaPRGO712HP Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 =3D match ls with > | [] -> [] > | 0 :: tl -> drop_zero tl > | hd :: tl -> hd :: drop_zero tl > ;; Hi, It isn't a =AB short circuit =BB : 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 --CEiMcfPkHBV12cs9QKWxuCUaPRGO712HP Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJSi+IKAAoJEPv4tP2UoeSeXxgP/2NcQVAX0kot5nnyY1JF2CNV 8uDEVaBS7ju/dLg34/AMzEM9bpbPP8ZBKyi9lTTKoU1KGIEkXA3LHfdtqnyLzBBH k53N0/ZVnLbunbmdj7unyWIYvvcmGEK4NjBzuoEO0VA5HMyggCxVJN9j/sfiN2Up R+OFS+DYR8X1egARpyzCbX1Q6cS8miVWVTrjYfhsVqGjaSinHNF4t2/He8n9igMr URPEioYlkRVA6pd53UCZzo6t6YDekUxe8ep8rjC4Hk0nfnhNE/54dfX+FJOKcJiL BVZqZQvRhWmrHBa19a/y7+g28hoIrQaD40ghHnTuR1Sf4jyyi/Y8kVrpN4JNCbmo 1uK6ZaiotD5nC76q3mjnYM3pkyPhsA+0/13Mc71Vsbn0c7Xyo6+xd1FZbxSnB7JB HYFZEGbjwmXJDDA4f64k8qoaEnl6vN7xULTJ8mvFVw1lRrwwfmngWXnRpioGHqfs BqjRSLpZaiR+Bi8ala9+b5nJkUXWeF4ZAhbDBy3SZMilaPV0BSmF8s3Xva8vucQU K43bbkYLSR7TqzPSmrOtUbh0DVhlL4W9XkPGGG4l+uTG7CM9uWcGIQjHccPfey0B m7EGoNQAAjstcip0jMpht+OWcqSRhGFGPoTubis5eoNqDJzxJTSsmEenWKxdQvAY vvLOm77vse2zaNXX/QCX =SEvD -----END PGP SIGNATURE----- --CEiMcfPkHBV12cs9QKWxuCUaPRGO712HP--