From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by c5ff346549e7 (Postfix) with ESMTP id 3817A5D6 for ; Fri, 9 Aug 2019 14:39:52 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.64,364,1559512800"; d="scan'208,217";a="394969727" Received: from sympa.inria.fr ([193.51.193.213]) by mail2-relais-roc.national.inria.fr with ESMTP; 09 Aug 2019 16:39:50 +0200 Received: by sympa.inria.fr (Postfix, from userid 20132) id 975D57EF0A; Fri, 9 Aug 2019 16:39:50 +0200 (CEST) Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id CCAB47ED21 for ; Fri, 9 Aug 2019 16:39:38 +0200 (CEST) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-qk1-f172.google.com IronPort-PHdr: =?us-ascii?q?9a23=3AHdWvtRUoKhyN3CTxmA9pdQirSc/V8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYbBWHt8tkgFKBZ4jH8fUM07OQ7/m6HzVZvt3e7zgrS99lb1c9k8?= =?us-ascii?q?IYnggtUoauKHbQC7rUVRE8B9lIT1R//nu2YgB/Ecf6YEDO8DXptWZBUhrwOhBo?= =?us-ascii?q?KevrB4Xck9q41/yo+53Ufg5EmCexbal9IRmrswndrNQajZZgJ6o+yBbEoGZDdv?= =?us-ascii?q?hLy29vOV+dhQv36N2q/J5k/SRQuvYh+NBFXK7nYak2TqFWASo/PWwt68LlqRfM?= =?us-ascii?q?TQ2U5nsBSWoWiQZHAxLE7B7hQJj8tDbxu/dn1ymbOc32Sq00WSin4qx2RhLklD?= =?us-ascii?q?sLOjgk+2zMlMd+kLxUrw6gpxxnwo7bfoeVNOZlfqjAed8WXHdNUtpNWyBEBI63?= =?us-ascii?q?cokBAPcbPetAoIb9qVkBoxuwCwevGe3h1CNHi2Ts0qEmyeksCx3K0BAiEt8IrX?= =?us-ascii?q?/arM/1NKAXUe2tzafH1y7Mb+lX2Tjj7IjDbw0vru2MXb1ua8re11MvHB7Cg1Wf?= =?us-ascii?q?s4PqJCmV1uUTvGif9eZgTv6gi245pAFrvDev3NwhiobMho0Py1DE8T91z5oyJd?= =?us-ascii?q?29UUN2Z8OvHphItyyCKYd6XscvT3trtSs60LEKp4C3cDYQxJg6xRPTdfqKeJWS?= =?us-ascii?q?7B35TuaeOzJ4iWpleL2hgxay9lCtyujmWcm11FZGtzNFktrRunwU2Rzf98qKRu?= =?us-ascii?q?Vn8keu3jaP0A/T6uVaLkwuiaXbLJshzqYxlpoVr0vDAjf7lFvqgKKSbEkp+eil?= =?us-ascii?q?5/75brn4uJOQLZJ4hwPgPqg2n8ywG+U4MgwAX2iB/uS80aXu/ULjT7pRlP02k7?= =?us-ascii?q?fWsJTAKcQAuqG5AxFa0pw95BalFDqm39EYkmMGLFJBYh6Ik4/pO1TWLPDiEfi/?= =?us-ascii?q?m0iskCtsx/3eIrLuGJDNLnzanLflfLZ98FJcxREozdFf4pJUEqsOLOjyWk/3rt?= =?us-ascii?q?zYDwU2Pxa6w+b9W51B0dZUY2OEAqaDPOvt93rOrsAoJeSXLsdBojf2K9As4fjj?= =?us-ascii?q?nX4w31gHcv/684EQbSWXF/58IkidKUHngtobHH1C6gU3RvbrhVnESjVTamy/RY?= =?us-ascii?q?oz4zg6DMStCoKVFdPlu6CIwCruRs4eXWtBEF3ZVC6wL9zZCcdJUzqbJ4paqhJB?= =?us-ascii?q?VbWlTNV/hxSntQu/0rk+a+SNpXdeupXk29x4oebUkENqrGAmP4Gmy2iIClpMsC?= =?us-ascii?q?YQXTZvhfJwpEV8zhGI1q0q26UJR+wW3OtAV0IBDbCZyuV7D97oXQeYJ4WGTV+n?= =?us-ascii?q?RpOtBjRjF98=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BuAAArhU1dhqzeVdFmHQEBBQEHBQGBV?= =?us-ascii?q?QYBCwGDVTMqhB6BHYJeiymCD4lsdI4vgXsJAQMBDC8BAYQ/AoJhGwcBBDIHDgE?= =?us-ascii?q?EAQEEAQEEAQMHARMBAQEICwsIKYUuDII6KQGCZwECAgEjHQEbHQEDAQsGBQQHN?= =?us-ascii?q?wICIgERAQUBHAYTgyKBagEDDg+fWzyLIoEVBQEXgnsFhE0KGScNXwOBPQIHEoE?= =?us-ascii?q?iAYtjgVc/hCM+h0+CWASdGY0/bQcCgh9eBJNNG5g4pWkPIYE2DIF9MxojUDGCO?= =?us-ascii?q?4JCGoNYilVAMI8PAQE?= X-IPAS-Result: =?us-ascii?q?A0BuAAArhU1dhqzeVdFmHQEBBQEHBQGBVQYBCwGDVTMqhB6?= =?us-ascii?q?BHYJeiymCD4lsdI4vgXsJAQMBDC8BAYQ/AoJhGwcBBDIHDgEEAQEEAQEEAQMHA?= =?us-ascii?q?RMBAQEICwsIKYUuDII6KQGCZwECAgEjHQEbHQEDAQsGBQQHNwICIgERAQUBHAY?= =?us-ascii?q?TgyKBagEDDg+fWzyLIoEVBQEXgnsFhE0KGScNXwOBPQIHEoEiAYtjgVc/hCM+h?= =?us-ascii?q?0+CWASdGY0/bQcCgh9eBJNNG5g4pWkPIYE2DIF9MxojUDGCO4JCGoNYilVAMI8?= =?us-ascii?q?PAQE?= X-IronPort-AV: E=Sophos;i="5.64,364,1559512800"; d="scan'208,217";a="316025461" X-MGA-submission: =?us-ascii?q?MDGNcJVLGxxLMDX8t/JA8DvaMBJehPVhFDqoSY?= =?us-ascii?q?ZWiMUZV8onzno3NFdcK9lfAN2NhJhDzxe9cJyhirsxKtx2RONP60icaG?= =?us-ascii?q?vOdxyc7sBtmGU/2a7zhvMzZE5qJjpfE4uhk5cyp4xKgyLALwcKwesg9F?= =?us-ascii?q?GsL65tpZ5fqjYSXsdpOWpOMQ=3D=3D?= Received: from mail-qk1-f172.google.com ([209.85.222.172]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 09 Aug 2019 16:39:36 +0200 Received: by mail-qk1-f172.google.com with SMTP id s145so71806060qke.7 for ; Fri, 09 Aug 2019 07:39:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wVVQCg/uDzlh0xCHdQMCHzDPiM2BMZFLrTduEzqV6Jw=; b=Zw+0sIUQzvgHfnCLqBw/l7AeKWIfDzvVDY6/7iTut7pUWAI8Q5VrxFORUCMSWgHgXA ZkAlUTmsI4bDkVHbrbeWhNlDRLfZ4+nMB4Am2q+bpVcqtkFYc6G4y0n5yEY5E7yHuAyL CHTgX0waMpkSK1linreyeSOq0WBbkhafjBT0ouJeYnyZsI7mKkCyAx3WQDh3OrBYnE7T Smc/8XcE9i2pa1hqLroDCNtCz1dcQvaV8O6Qdyo3spKz28gX3l394/bnYBmbx2sUXRua sNpevHsh8zLSnnjg/e3GFilJ1E0cwuDAOxtj6YHg70VwV8RG4PT3Sp6tpexguBpTFJi+ 9MXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wVVQCg/uDzlh0xCHdQMCHzDPiM2BMZFLrTduEzqV6Jw=; b=L7f8KTaXWIARXzezq2AtwX63A/2Pgz/SrerULeLWvvn4lzFbuOhQ4ccTU0NZ6qtwG1 X1qxjh+03OCXHI9xjM4OZZarcPNp+k6kIWB4oFQY4Wpu0PB4zbJQ6Jrc8RHM61TJZFp5 5N7FE50hs5EpNdRCCemqGdEn7I2AX8WuUpf3A4MpZk6HDEzCt896ow+58X0j+tLkhyDs PwJYM1hWSyFPQeZ8OqkyQUPbUHDHNedH12LXsnDp6PdqRU3MzYHtT4JBuiZWpSdbuzGG H7njrP4in6B8U+3tERo6uwuXHkIgMcqCc0QV62D/WtgtuGjX4kwo+PKvsRZhDYok3B+7 hk3w== X-Gm-Message-State: APjAAAUIOFFPJ5Gfq1J9UXGGSZQ6IQtkMag7cAifsXsJQofzlolXnbwR /NPY5+MH/6nINqmvDbJfMpWhyYOyQD0js846Hswozw== X-Google-Smtp-Source: APXvYqxsOAODH6k8OFneWy3yUc+RICa/8IakfYFbTpsoCqIwboeu4hAqNgTrWiT36A/SI1Ig/LD27SZjD9vMJzcgyUk= X-Received: by 2002:a37:7604:: with SMTP id r4mr18059340qkc.395.1565361574980; Fri, 09 Aug 2019 07:39:34 -0700 (PDT) MIME-Version: 1.0 References: <20190809142719.ff4kogz4fq6r7vfr@annexia.org> In-Reply-To: <20190809142719.ff4kogz4fq6r7vfr@annexia.org> From: Gabriel Scherer Date: Fri, 9 Aug 2019 16:40:48 +0200 Message-ID: To: "Richard W.M. Jones" Cc: caml users Content-Type: multipart/alternative; boundary="0000000000009f2ff5058fb0242b" Subject: Re: [Caml-list] Syntax puzzle / suggestion Reply-To: Gabriel Scherer X-Loop: caml-list@inria.fr X-Sequence: 17751 Errors-to: caml-list-owner@inria.fr Precedence: list Precedence: bulk Sender: caml-list-request@inria.fr X-no-archive: yes List-Id: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --0000000000009f2ff5058fb0242b Content-Type: text/plain; charset="UTF-8" If you have an interface file (.mli) for this module, then adding item3 without putting it in all_items or in the .mli will result in an "unused value item3" warning (-w +32). There is no such warning in absence of .mli because, in that case, item3 may a priori be used from the outside. On Fri, Aug 9, 2019 at 4:28 PM Richard W.M. Jones wrote: > Let's imagine you have a list of named things, but you also want to > collect them up into a single list. For example: > > let item1 = "hello" > let item2 = "world" > let all_items = [ item1; item2 ] > > let () = > printf "item1 = %s\n" item1; > printf "all_items = %s\n" (String.concat ", " all_items) > > This is fine, but there's a danger that a programmer could add item3 > but forget to add it to the "all_items" list. (In the real world > problem to which this applies, my items are complex and lengthy > structures, and the "all-things-list" is well off the bottom of the > page when you're viewing the top item). > > My idea to fix this was to write: > > let all_items = [ > ("hello" as item1); > ("world" as item2); > ] > > Actually I was slightly surprised to find this doesn't compile. I > guess because "as" can only be used like this in patterns, not > expressions. Also the scoping is wrong because the "as item1" if it > worked probably wouldn't apply outside the list. > > I haven't worked out if it's possible to write this in ordinary OCaml, > although I suppose ppx could solve it. Any ideas if this is possible? > > Rich. > --0000000000009f2ff5058fb0242b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
If you have an interface file (.mli) for this module,= then adding item3 without putting it in all_items or in the .mli will resu= lt in an "unused value item3" warning (-w +32).
There i= s no such warning in absence of .mli because, in that case, item3 may a pri= ori be used from the outside.

On Fri, Aug 9, 2019 at 4:28 PM Richa= rd W.M. Jones <rich@annexia.org&= gt; wrote:
Let&#= 39;s imagine you have a list of named things, but you also want to
collect them up into a single list.=C2=A0 For example:

=C2=A0 let item1 =3D "hello"
=C2=A0 let item2 =3D "world"
=C2=A0 let all_items =3D [ item1; item2 ]

=C2=A0 let () =3D
=C2=A0 =C2=A0 printf "item1 =3D %s\n" item1;
=C2=A0 =C2=A0 printf "all_items =3D %s\n" (String.concat ", = " all_items)

This is fine, but there's a danger that a programmer could add item3 but forget to add it to the "all_items" list.=C2=A0 (In the real = world
problem to which this applies, my items are complex and lengthy
structures, and the "all-things-list" is well off the bottom of t= he
page when you're viewing the top item).

My idea to fix this was to write:

=C2=A0 let all_items =3D [
=C2=A0 =C2=A0 ("hello" as item1);
=C2=A0 =C2=A0 ("world" as item2);
=C2=A0 ]

Actually I was slightly surprised to find this doesn't compile.=C2=A0 I=
guess because "as" can only be used like this in patterns, not expressions.=C2=A0 Also the scoping is wrong because the "as item1&quo= t; if it
worked probably wouldn't apply outside the list.

I haven't worked out if it's possible to write this in ordinary OCa= ml,
although I suppose ppx could solve it.=C2=A0 Any ideas if this is possible?=

Rich.
--0000000000009f2ff5058fb0242b--