News for hackers. Stuff that matters.
Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @10:17AM (#21946560)
> all languages are just copying each other at this point. I know C++ hates to be left out of anything so maybe this is appropriate, but to me its really destroying the ecosystem. It was great to have different languages having different paradigms but now you can do everything in everything

I don't think you can do everything in everything. Try working with lazy immutable data structures in Rust, for one.

Or look at Dart - now has "non-nullable types," monadic error handling (sort of), but of course the whole thing is on shaky foundations so what's it worth?

Re:C++ Pattern Matching Proposal [pdf] by derefr on Friday January 03, 2020 @11:07AM (#21947085)
> Try working with lazy immutable data structures in Rust.

I don’t think this is that hard; you “just” need to construct the data structures as elements of an object-graph data structure, and then retrieve your data through an explicit thunk of the object-graph itself.

In lazy languages the object-graph data structure is implicit, but that doesn’t mean that the Rust version of the call site code needs to be any more verbose. It’s just the definitions of the data structures themselves that would be more unwieldy. (And you could probably build some generic lazy container types and mostly work with those.)

Think: what Objective-C does with autorelease-pool objects.

Re:C++ Pattern Matching Proposal [pdf] by steveklabnik on Friday January 03, 2020 @11:30AM (#21947373)
Here’s what immutable data structures look like in Rust: https://docs.rs/im/14.1.0/im/
Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @03:29PM (#21949982)
None are lazy, however.
Re:C++ Pattern Matching Proposal [pdf] by ChrisSD on Friday January 03, 2020 @10:43AM (#21946815)
> Try working with lazy immutable data structures in Rust, for one.

Why is that an issue?

Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @10:58AM (#21946992)
Well, it doesn't have the runtime to support laziness properly.
Re:C++ Pattern Matching Proposal [pdf] by fctorial on Friday January 03, 2020 @11:47AM (#21947588)
Why would lazy data structures need a runtime? Some kind of GC is necessary for immutable data structures, but wouldn't iterators and generators be enough for implementing laziness?
Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @03:32PM (#21950014)
> wouldn't iterators and generators be enough for implementing laziness?

If you can implement lazy finger trees with iterators I'd love to see it :)

Re:C++ Pattern Matching Proposal [pdf] by ChrisSD on Friday January 03, 2020 @11:10AM (#21947119)
Sure, it doesn't have much of a runtime at all but Rust does give a firm foundation to build on. Using an `Option` or the `once_cell` library is pretty ergonomic. At worse you use a function call to get a reference to the value instead of using it directly.
Re:C++ Pattern Matching Proposal [pdf] by DougBTX on Friday January 03, 2020 @11:26AM (#21947309)
Agreed, Rust can certainly handle lazy evaluation. All the iterator types for example are lazy, hence the .collect() method which eagerly evaluates a lazy collection.

Hiding the fact that a lazy value needs to be mutated to initialise it is a little more work (since a nice API lets the user treat the value as if it doesn’t need to be mutated), but is certainly possible.

Re:C++ Pattern Matching Proposal [pdf] by vmchale on Friday January 03, 2020 @03:31PM (#21950003)
> All the iterator types for example are lazy,

It's not proper laziness as defined in Okasaki's thesis/book. One needs more complex things like lazy finger trees.

Re:C++ Pattern Matching Proposal [pdf] by paulddraper on Friday January 03, 2020 @06:39PM (#21951519)
The iterator is lazy.

The language is not.