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 3B6397EEBF for ; Tue, 4 Aug 2015 15:50:45 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of hendrik@topoi.pooq.com) identity=pra; client-ip=69.165.131.134; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="hendrik@topoi.pooq.com"; x-sender="hendrik@topoi.pooq.com"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of hendrik@topoi.pooq.com) identity=mailfrom; client-ip=69.165.131.134; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="hendrik@topoi.pooq.com"; x-sender="hendrik@topoi.pooq.com"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@april.topoi.pooq.com) identity=helo; client-ip=69.165.131.134; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="hendrik@topoi.pooq.com"; x-sender="postmaster@april.topoi.pooq.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BlBwDfwsBV/4aDpUVbhDOCecIXAoF9AQEBAQEBgQuEJAEBBDIBVgsYCSUPBRiIcssyAQEIAiCLT4UPF4MBgRQFlHqMTgJPeJQqg2QmhBkign0BAQE X-IPAS-Result: A0BlBwDfwsBV/4aDpUVbhDOCecIXAoF9AQEBAQEBgQuEJAEBBDIBVgsYCSUPBRiIcssyAQEIAiCLT4UPF4MBgRQFlHqMTgJPeJQqg2QmhBkign0BAQE X-IronPort-AV: E=Sophos;i="5.15,609,1432591200"; d="scan'208";a="172637634" Received: from topoi.pooq.com (HELO april.topoi.pooq.com) ([69.165.131.134]) by mail2-smtp-roc.national.inria.fr with ESMTP; 04 Aug 2015 15:50:43 +0200 Received: by april.topoi.pooq.com (Postfix, from userid 1001) id AC0601A06B9; Tue, 4 Aug 2015 09:50:41 -0400 (EDT) Date: Tue, 4 Aug 2015 09:50:41 -0400 From: Hendrik Boom To: caml-list@inria.fr Message-ID: <20150804135041.GA30991@topoi.pooq.com> References: <55BF6F1C.3050705@bioquant.uni-heidelberg.de> <55BF75F6.1040006@bioquant.uni-heidelberg.de> <8E1A640CE3374EB492981ADB0A2DA5C6@erratique.ch> <20150804065134.GA10576@dione.int.eideticdew.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20150804065134.GA10576@dione.int.eideticdew.org> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [Caml-list] destructive local opens On Tue, Aug 04, 2015 at 08:51:34AM +0200, Petter Urkedal wrote: > On 2015-08-03, Daniel Bünzli wrote: > > Le lundi, 3 août 2015 à 15:08, Nils Becker a écrit : > > > It's possible that people actually want M.() to mean let open! more > > > often than let open. For me I think that's the case. > > > > If you are in the vector case, I don't think that's the case. With Gg [1] I often had the following kind of subtly wrong code (can't remember the exact details but something similar): > > > > let ox = V2.((dot v ox) * ox) in > > V2.(3 * ox + oy) > > > > The reality is that M.() is inherently dangerous, especially from an API evolution perspective where new identifiers with matching type may get introduced later leading to silent semantic changes in your code. So we should not encourage people to use M.!() as it's going to make the problem even more acute. Besides we should have that 44 warning by default so that we see the problems, but for now it's impossible to live with 44 and a Gg like library. > > This suggests another option. If type information is available at the > point this warning is emitted, then the warning could be issued only in > the case when the type of the shadowing identifier matched that of the > shadowed identifier. > > This assumes the common case for shadowing is to redefine operators or > common functions at a custom type, the use of M.() being an alternative > to overloading. Loosely the warning should be emitted if the chosen > identifier is not the one which would have been chosen by some sensible > overloading scheme, but instead we make a simple estimate. > > This could still go wrong, since the type required by the context may be > general than the type of both the shadowed and shadowing terms, so a > better rule might be to issue the warning if both are admissible in the > given context, though my guess is that's harder to implement. The rules for shadowing vs overloading in Algol 68 were roughly the following: If it is possible for an operators to have operands such that (considering all the available implicit type conversions) either operator could validly apply to them, then it is forbidden to define them in the same scope, and if they are defined in nested scopes, the inner declaration will shadow the outer. If it wa not possible for this ambiguity to arise, then you just had overloading. There was no additional scope-disambiguation syntax. This worked quite well in practice. Adding a shadowing-warning on everything on top of this could be a convenience for avoiding confusing code. -- hendrik