caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Allsopp <dra-news@metastack.com>
To: "Petter A. Urkedal" <paurkedal@gmail.com>,
	Goswin von Brederlow <goswin-v-b@web.de>
Cc: caml users <caml-list@inria.fr>
Subject: RE: [Caml-list] destructive local opens
Date: Wed, 5 Aug 2015 10:16:39 +0000	[thread overview]
Message-ID: <E51C5B015DBD1348A1D85763337FB6D9E9D88238@Remus.metastack.local> (raw)
In-Reply-To: <CALa9pHSgkUHqpk8310GaHfDv1wAy1bBv--FbxG6sM0c8p6PFqg@mail.gmail.com>

Petter A. Urkedal wrote:
> 2015-08-04 11:33 GMT+02:00 Goswin von Brederlow <goswin-v-b@web.de>:
> > 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.
> >
> > I like the idea but how feasable is it? Most of the time I figure the
> > type being infered from the operator being used. The use of M.(*)
> > makes it the custom type while simple (*) would make it int. The type
> > system would have to track the ambiguity until some other use of the
> > arguments or result decide the proper type. And if it doesn't resolve
> > then emit the warning.
> 
> Yes, it's probably not that easy to implement.  Not familiar with the code
> base.  At least it requires postponing the warning till type information
> is available, and maybe cluttering the parse tree with sub-nodes
> containing the types and locations of shadowed identifiers.
> The types at the point the check is made will have been analysed under the
> assumption that the right resolution was made.

I asked similar a few years ago on the list for general let-shadowing[1].

I haven't checked whether it's still working in latest ocaml/camlp4, as I vaguely recall that if-then-else shadowing isn't correctly handled in the filter, and I ended up having to disable it in the project I was using it for, but it was a reasonably short camlp4 filter and ocamllex script to do the post-processing, so I can't imagine that this similar case would be that bad in the compiler itself. I've chucked the original code at https://github.com/dra27/pf_shadow for interest.


David


[1] http://caml.inria.fr/pub/ml-archives/caml-list/2008/08/5b882a133318d913dd7aaa0abacf36d7.en.html

  reply	other threads:[~2015-08-05 10:16 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-03 13:39 Nils Becker
2015-08-03 13:43 ` Thomas Refis
2015-08-03 13:45 ` Daniel Bünzli
2015-08-03 13:47   ` Daniel Bünzli
     [not found]     ` <55BF75F6.1040006@bioquant.uni-heidelberg.de>
2015-08-03 14:24       ` Daniel Bünzli
2015-08-03 14:37         ` Gabriel Scherer
2015-08-03 14:43           ` Daniel Bünzli
2015-08-03 15:10           ` octachron
2015-08-03 15:22             ` Daniel Bünzli
2015-08-03 16:13               ` octachron
2015-08-03 16:51                 ` Daniel Bünzli
2015-08-03 17:18                   ` Hendrik Boom
2015-08-03 17:59                   ` octachron
2015-08-06 13:23                     ` RE : " moreno pedro
2015-08-04  6:51         ` Petter Urkedal
2015-08-04  9:33           ` Goswin von Brederlow
2015-08-05  6:40             ` Petter A. Urkedal
2015-08-05 10:16               ` David Allsopp [this message]
2015-08-06  9:35               ` Goswin von Brederlow
2015-08-04 13:50           ` Hendrik Boom
2015-08-04  9:26         ` Goswin von Brederlow
2015-08-04  9:38           ` Daniel Bünzli
2015-08-04 12:26             ` vrotaru.md
2015-08-04 13:12               ` David Allsopp
2015-08-04 13:17                 ` Jeremy Yallop
2015-08-04 13:54                   ` vrotaru.md
2015-08-04 15:25                   ` Drup
2015-08-04 22:22                     ` vrotaru.md
2015-08-04 22:55                       ` Hendrik Boom
2015-08-05  4:52                         ` Gabriel Scherer
2015-08-04 13:14               ` Ivan Gotovchits
2015-08-14 10:55                 ` Goswin von Brederlow
2015-08-14 11:28                   ` Drup
2015-08-18 11:11                     ` Goswin von Brederlow
2015-08-18 12:52                       ` David Allsopp
2015-08-18 13:00                         ` Gabriel Scherer
2015-08-18 22:26                           ` Anthony Tavener
2015-08-19 13:55                             ` Oleg
2015-08-19 14:13                               ` John Whitington
2015-08-19 15:47                                 ` Hendrik Boom
2015-08-19 15:52                             ` Hendrik Boom
2015-08-19 18:09                               ` Anthony Tavener
2015-08-19 15:55                             ` Simon Cruanes
2015-08-19 16:42                               ` Arthur Wendling
2015-08-19 21:15                               ` octachron
2015-08-20  8:06                                 ` Romain Bardou
2015-08-20 17:03                                   ` Yotam Barnoy
2015-08-20 19:19                                     ` Erkki Seppala
2015-08-06  9:23               ` Goswin von Brederlow
2015-08-06  9:21             ` Goswin von Brederlow
2015-08-06 10:19               ` Daniel Bünzli
2015-08-06 13:36                 ` Hendrik Boom
2015-08-14 10:57                   ` Goswin von Brederlow
2015-08-17 10:17 Nils Becker
2015-08-17 14:26 ` Gabriel Scherer
2015-08-17 15:11   ` Nils Becker
2015-08-17 15:17     ` Drup
2015-08-17 15:18     ` Gabriel Scherer
2015-08-17 18:31       ` Hendrik Boom

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=E51C5B015DBD1348A1D85763337FB6D9E9D88238@Remus.metastack.local \
    --to=dra-news@metastack.com \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    --cc=paurkedal@gmail.com \
    /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).