caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] destructive local opens
@ 2015-08-03 13:39 Nils Becker
  2015-08-03 13:43 ` Thomas Refis
  2015-08-03 13:45 ` Daniel Bünzli
  0 siblings, 2 replies; 59+ messages in thread
From: Nils Becker @ 2015-08-03 13:39 UTC (permalink / raw)
  To: caml-list

Hi,

this is a small syntax suggestion which I thought I should share;
apologies if this is nonsense or has been already decided against.

Currently we have

let open! M in
...

to indicate that we do intend to shadow definitions in the current scope
by those in M. This avoids getting warning 44 on compilation. I find
that quite useful.

Would it be a good idea to have the same thing
for local opens with the dot syntax? M.(...) produces warning 44
currently, but a proposed new syntax

M.!(...)
or
M!(...)

or something of the kind would suppress it. Obviously it should not
interfere with references.

I came across this wish after defining a small Vector module which
overrides (+) to mean vector addition. Then formulas are conveniently
written M.(v + w) but that means I get 44. Of course I could define (+|)
instead but why not make use of namespaces if we can.

^ permalink raw reply	[flat|nested] 59+ messages in thread
* Re: [Caml-list] destructive local opens
@ 2015-08-17 10:17 Nils Becker
  2015-08-17 14:26 ` Gabriel Scherer
  0 siblings, 1 reply; 59+ messages in thread
From: Nils Becker @ 2015-08-17 10:17 UTC (permalink / raw)
  To: caml-list

Sorry for the late comment.

The mentioned bug:

> let ox = V2.((dot v ox) * ox) in
> V2.(3 * ox + oy)

because V2 also has V2.ox sure is nasty. But the same would happen with
a local 'let open V2'.

let ox =
    let open V2 in
    (dot v ox) * ox in
V2.(3 * ox + oy)

For ease of reasoning I think it may be a good idea to make M.(...) and
M.!(...) behave in exactly the same way as let open and let open!
respectively, including error messages. This would probably forbid
distinguishing between infix operators and the rest.

(Admittedly, in the latter example one would be tempted to combine the
local opens here which would make things clearer)

> The reality is that M.() is inherently dangerous,

When one uses a (destructive) local open one trades the possibility of
ambiguity for conciseness. In a few cases the conciseness is really,
really important, so that this trade-off is worth it. (I'm thinking
about math.) The existence of let open! in the language says that there
is some consensus that ambiguity is sometimes acceptable.


>    The benefit is that I can understand what is happening by only
> looking at the
>    expression I'm reading. With your proposal I also need to go read
> the library
>    source to understand what is happening.

It's not that bad. Destructive opens mean one has to know the shadowing
module's signature. Only the values exported in the signature actually
shadow anything (I just tried it out) so one does _not_ need to know the
module source!

Right now, one cannot really use M.(...) to shadow without deactivating
warning 44. This is not ideal. With the syntax M.!(...) one would be
forced to declare shadowing intent and 44 could be switched on. Then

let ox = V2.!((dot v ox) * ox) in
V2.!(3 * ox + oy)

would still let the same bug happen but at least one was forced to write
an exclamation mark which should give a feeling of "be careful about
shadowing here!". Would this not be enough?


n.

^ permalink raw reply	[flat|nested] 59+ messages in thread

end of thread, other threads:[~2015-08-20 19:19 UTC | newest]

Thread overview: 59+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-03 13:39 [Caml-list] destructive local opens 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
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

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).