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 361495D6 for ; Fri, 9 Aug 2019 14:53:18 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.64,364,1559512800"; d="scan'208";a="394971002" Received: from sympa.inria.fr ([193.51.193.213]) by mail2-relais-roc.national.inria.fr with ESMTP; 09 Aug 2019 16:53:17 +0200 Received: by sympa.inria.fr (Postfix, from userid 20132) id 291CB7EF0E; Fri, 9 Aug 2019 16:53:17 +0200 (CEST) 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 2896D7ED21 for ; Fri, 9 Aug 2019 16:53:05 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=josh@berdine.net; spf=Pass smtp.mailfrom=josh@berdine.net; spf=Pass smtp.helo=postmaster@out4-smtp.messagingengine.com IronPort-PHdr: =?us-ascii?q?9a23=3A13hJBhUnWTAPilzYTKCTOlApq6TV8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYbBWPt8tkgFKBZ4jH8fUM07OQ7/m6HzVZvt3e4TgrS99lb1c9k8?= =?us-ascii?q?IYnggtUoauKHbQC7rUVRE8B9lIT1R//nu2YgB/Ecf6YEDO8DXptWZBUhrwOhBo?= =?us-ascii?q?KevrB4Xck9q41/yo+53Ufg5EmCexbal9IRmrswndrNQajZZgJ6o+yBbEpmZDdv?= =?us-ascii?q?hLy29vOV+dhQv36N2q/J5k/SRQuvYh+NBFXK7nYak2TqFWASo/PWwt68LlqRfM?= =?us-ascii?q?TQ2U5nsBSWoWiQZHAxLE7B7hQJj8tDbxu/dn1ymbOc32Sq00WSin4qx2RhLklD?= =?us-ascii?q?sLOjgk+2zMlMd+kLxUrw6gpxxnwo7bfoeVNOZlfqjAed8WXHdNUtpNWyBE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QpVNtomI0EblxxGtOvyBbOw3jyDg=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BPCAB0iE1dhxwEb0JmHQEBBQEHBQGBZ?= =?us-ascii?q?4MITwExKo0ahimBaiWDZ5cjCQEDAQwvAQGEPwKCYRwGAQQ0EwEEAQEEAQEEAQM?= =?us-ascii?q?HARMBAQEIDQkIKYUuDII6KQGCZwECAgFAAQE4BAsLRlcGgzWBfA+qUoIkgnoBA?= =?us-ascii?q?QWCSIR2CYE0i2QXgX+BOAwTgkw+iAGCJqpcbQkCgh1iAZNnjTgUimyleIFngXl?= =?us-ascii?q?7CjsqAYJBgkIag1iEWYV7PgEBMY8PAQE?= X-IPAS-Result: =?us-ascii?q?A0BPCAB0iE1dhxwEb0JmHQEBBQEHBQGBZ4MITwExKo0ahim?= =?us-ascii?q?BaiWDZ5cjCQEDAQwvAQGEPwKCYRwGAQQ0EwEEAQEEAQEEAQMHARMBAQEIDQkIK?= =?us-ascii?q?YUuDII6KQGCZwECAgFAAQE4BAsLRlcGgzWBfA+qUoIkgnoBAQWCSIR2CYE0i2Q?= =?us-ascii?q?XgX+BOAwTgkw+iAGCJqpcbQkCgh1iAZNnjTgUimyleIFngXl7CjsqAYJBgkIag?= =?us-ascii?q?1iEWYV7PgEBMY8PAQE?= X-IronPort-AV: E=Sophos;i="5.64,364,1559512800"; d="scan'208";a="394970904" X-MGA-submission: =?us-ascii?q?MDGnnySiU2xNHDUMuoWufebm8KgYbakWB1YYqe?= =?us-ascii?q?/8ScPUFygXjJnTxaTNtVNGAZgE6fS7j1Fd59P+LYccSVNKUWk2Z9mUUB?= =?us-ascii?q?APiOr+6Hy42tr2Kd/VSxAqfuV1xUOxB6KXjBMz2PsEKysDL72Vtldye7?= =?us-ascii?q?CK1n2zY8ic482CcmJsBLdPrQ=3D=3D?= Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Aug 2019 16:53:04 +0200 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id F347921C48 for ; Fri, 9 Aug 2019 10:53:02 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 09 Aug 2019 10:53:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=berdine.net; h= resent-from:resent-to:resent-date:resent-message-id:from:to :subject:date:message-id:in-reply-to:references:mime-version :content-type; s=fm3; bh=WbF//BtKGN3EqSXDBHA1zurjyCJNEC4dBQpUWNw zaac=; b=uvuWwu8b1vttNyjpW4BOje+7V7DGKOuMQZmAvB2QdcuGfScfiI9u2xY XfNFUap5Gf2gEBDP4uDk1zMEz65wmAsI0P2giso22N/fZ4WJ3svScqf8mS+Bymub YaXNN8nLIeukP1FfQ/FqaLDyGjnpD21rfoyECRrB9I6Fh3F6xmzHu6SHcZTpAcfa z2w1rSGlEmYAf7uxLDHW18DfJY5U+466GbGXBmCXxN9fEv7VqOPEqdfOAupY0Lsl EWfH78okfKvu4JtoIWqOBz950rjUUTSeKghPVWVKiaIFYT2Pz9Qd/OvZIw74xLW2 LoXL5E6Lq/Sgo0LPDAwNDu8ci0JnoqA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:resent-date:resent-from :resent-message-id:resent-to:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=WbF//BtKGN3EqSXDB HA1zurjyCJNEC4dBQpUWNwzaac=; b=kqJ6+ejv7j7qinF8OryLj7EytTCx7JVzN eMjwKmAtI5vKanCjddEoEUl+VDvg6TD8jm+j6h92/qpThbzxcsB3cTNd+IliNxfp Giw083Pu567ZH5F/YzGGNPDjBjyhpwl9vYPLC+ly8hRRItuUnXvw2EkksEC3QrOg rLWe5XVKI2dvwA+NOaXppDc4HMWcRQ2cMzg/MbpQUwDWzfEyU1xoOenJBGTJtaps 7thtLhlYWRldk4yrJt4IoXCu4KDMtZ9KRkFQJJQElmPmSmA9Idg3OyHL1em/cIyT 3z8+nFPLUCY3vFPt+U6zu6NlUnDdzz3vxeZXHiR7QsLtR5T3vUeyw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddruddujedgkedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffoffkjghfgggtsehttdhmtdertddtnecuhfhrohhmpedflfhoshhh uceuvghrughinhgvfdcuoehjohhshhessggvrhguihhnvgdrnhgvtheqnecukfhppedule elrddvtddurdeiiedrtdenucfrrghrrghmpehmrghilhhfrhhomhepjhhoshhhsegsvghr ughinhgvrdhnvghtnecuvehluhhsthgvrhfuihiivgepud X-ME-Proxy: Received: from [172.16.16.231] (unknown [199.201.66.0]) by mail.messagingengine.com (Postfix) with ESMTPA id 0E684380074 for ; Fri, 9 Aug 2019 10:53:01 -0400 (EDT) Resent-From: "Josh Berdine" Resent-To: caml-list Resent-Date: Fri, 09 Aug 2019 15:53:00 +0100 Resent-Message-Id: <9E081E64-8DF5-4969-8A26-C779B4C52D53@berdine.net> From: "Josh Berdine" To: "Richard W.M. Jones" Date: Fri, 09 Aug 2019 15:51:39 +0100 X-Mailer: MailMate (1.12.5r5635) Message-ID: In-Reply-To: <20190809142719.ff4kogz4fq6r7vfr@annexia.org> References: <20190809142719.ff4kogz4fq6r7vfr@annexia.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Caml-list] Syntax puzzle / suggestion Reply-To: "Josh Berdine" X-Loop: caml-list@inria.fr X-Sequence: 17754 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: What about good old-fashioned state: let all_items = ref [] let add_item item = all_items := (item :: !all_items, item) let item1 = add_item "hello" let item2 = add_item "world" let all_items = List.rev !all_items On 9 Aug 2019, at 15:27, 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.