* [Caml-list] Operator for Lazy.force?
@ 2013-10-30 18:51 Lukasz Stafiniak
2013-10-30 21:07 ` Dario Teixeira
0 siblings, 1 reply; 6+ messages in thread
From: Lukasz Stafiniak @ 2013-10-30 18:51 UTC (permalink / raw)
To: Caml, batteries-discuss
[-- Attachment #1: Type: text/plain, Size: 163 bytes --]
Hello,
Shouldn't we have, in standard libraries, a prefix operator for forcing
lazy values, comparable to `!` for reference cells and `.!` for MetaOCaml's
"run"?
[-- Attachment #2: Type: text/html, Size: 216 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Operator for Lazy.force?
2013-10-30 18:51 [Caml-list] Operator for Lazy.force? Lukasz Stafiniak
@ 2013-10-30 21:07 ` Dario Teixeira
2013-10-30 21:33 ` Dmitry Grebeniuk
0 siblings, 1 reply; 6+ messages in thread
From: Dario Teixeira @ 2013-10-30 21:07 UTC (permalink / raw)
To: Lukasz Stafiniak, Caml, batteries-discuss
Hi,
> Shouldn't we have, in standard libraries, a prefix operator for forcing lazy values,
> comparable to `!` for reference cells and `.!` for MetaOCaml's "run"?
Indeed, the following operator definition is pretty common on OCaml code in the wild:
let (!!) = Lazy.force
However, I'm not sure it should be part of a standard library. There are projects which
do not use Lazy, and instead define the (!!) operator to be something else convenient
for whatever task they perform.
Best regards,
Dario Teixeira
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Operator for Lazy.force?
2013-10-30 21:07 ` Dario Teixeira
@ 2013-10-30 21:33 ` Dmitry Grebeniuk
2013-10-31 11:10 ` Dario Teixeira
2013-11-01 15:49 ` Damien Doligez
0 siblings, 2 replies; 6+ messages in thread
From: Dmitry Grebeniuk @ 2013-10-30 21:33 UTC (permalink / raw)
To: Dario Teixeira
Hello.
> However, I'm not sure it should be part of a
> standard library. There are projects which
> do not use Lazy, and instead define the (!!)
> operator to be something else convenient
> for whatever task they perform.
So theirs ( !! ) operator will override Pervasives' one.
What's the problem? Anyway projects you've mentioned don't use Lazy,
so there's no chance of "operator clash".
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Operator for Lazy.force?
2013-10-30 21:33 ` Dmitry Grebeniuk
@ 2013-10-31 11:10 ` Dario Teixeira
2013-11-01 15:49 ` Damien Doligez
1 sibling, 0 replies; 6+ messages in thread
From: Dario Teixeira @ 2013-10-31 11:10 UTC (permalink / raw)
To: Dmitry Grebeniuk, OCaml mailing-list
Hi,
> So theirs ( !! ) operator will override Pervasives' one.
> What's the problem? Anyway projects you've mentioned don't use
> Lazy, so there's no chance of "operator clash".
I don't think it's that simple. Once (!!) is "standardised" to be Lazy.force,
people encountering it when reading third-party code will expect it to have
that function, and are less likely to carefully read the third-party code to
see if it has been redefined. This is not the case right now: though (!!)
is often defined as Lazy.force, this is by no means universal, so one
still has to check.
With the above in mind, standardising (!!) to be Lazy.force will in effect
make it a bad practice to redefine it, as is the case for the other standard
operators. Note that the only commonly redefined operators are the
arithmetic ones, and even those tend to be redefined only when there's
little chance of shadowing (cf. Batteries Float module).
All and all, standardising (!!) to be Lazy.force would result in many projects
having to use (!!!) instead, reserving the more convenient (!!) to the small
number of projects that make heavy use of Lazy.force.
Best regards,
Dario Teixeira
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Operator for Lazy.force?
2013-10-30 21:33 ` Dmitry Grebeniuk
2013-10-31 11:10 ` Dario Teixeira
@ 2013-11-01 15:49 ` Damien Doligez
2013-11-02 19:03 ` David Allsopp
1 sibling, 1 reply; 6+ messages in thread
From: Damien Doligez @ 2013-11-01 15:49 UTC (permalink / raw)
To: caml users
Hello,
On 2013-10-30, at 22:33, Dmitry Grebeniuk wrote:
> So theirs ( !! ) operator will override Pervasives' one.
> What's the problem? Anyway projects you've mentioned don't use Lazy,
> so there's no chance of "operator clash".
It cannot be in Pervasives, since that would introduce a circular
dependency with Lazy. It doesn't belong in Pervasives anyway.
The best you can do is define it in a submodule of Lazy, for example
Lazy.Op, and let the user do
open Lazy.Op;;
to access the operator without too much verbosity.
-- Damien
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [Caml-list] Operator for Lazy.force?
2013-11-01 15:49 ` Damien Doligez
@ 2013-11-02 19:03 ` David Allsopp
0 siblings, 0 replies; 6+ messages in thread
From: David Allsopp @ 2013-11-02 19:03 UTC (permalink / raw)
To: caml users
Damien Doligez wrote:
> On 2013-10-30, at 22:33, Dmitry Grebeniuk wrote:
>
> > So theirs ( !! ) operator will override Pervasives' one.
> > What's the problem? Anyway projects you've mentioned don't use Lazy,
> > so there's no chance of "operator clash".
>
> It cannot be in Pervasives, since that would introduce a circular
> dependency with Lazy. It doesn't belong in Pervasives anyway.
Out of belligerent curiosity only, is that definitely true? lazy.mli doesn't create an opaque type for 'a Lazy.t so wouldn't
external ( !! ) : 'a lazy_t -> 'a = "%lazy_force"
in pervasives.ml/mli work out of the box and to all intents and purposes have the right effect?
Even if you wanted to have the neater type 'a Lazy.t -> 'a, lazy.ml only refers to a handful of trivial externals and constants in obj.ml and only requires ( <> ) and ( || ) from Pervasives. Isn't it the case that as Pervasives would then only refer to a *type* in Lazy that you wouldn't have the (presumably unwanted) side-effect of even "Hello World" being linked with Lazy?
So either with some very minor internal code duplication (or a bit of pre-processing), is there anything else which means that you couldn't add that declaration to Pervasives without the circular dependency?
I agree that it probably doesn't belong there (although I can see the other side, given that the lazy keyword is, um, "pervasive") - just curious as to if it's possible :o)
David
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-11-02 19:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-30 18:51 [Caml-list] Operator for Lazy.force? Lukasz Stafiniak
2013-10-30 21:07 ` Dario Teixeira
2013-10-30 21:33 ` Dmitry Grebeniuk
2013-10-31 11:10 ` Dario Teixeira
2013-11-01 15:49 ` Damien Doligez
2013-11-02 19:03 ` David Allsopp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox