Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default list laziness vs strictness #29

Open
krainboltgreene opened this issue Nov 10, 2013 · 5 comments
Open

Default list laziness vs strictness #29

krainboltgreene opened this issue Nov 10, 2013 · 5 comments

Comments

@krainboltgreene
Copy link
Member

Laziness is the default with lists but perhaps we could consider making them strict unless you ask for them to be lazy???

@harukizaemon
Copy link
Contributor

Yes, I'd thought the same thing. Perhaps instead of (or as well as) you could nominate whether a block used in a sequence is volatile or not/expensive or not and change the caching strategy accordingly.

@krainboltgreene
Copy link
Member Author

Sounds like a full on feature, moving to 1.1.0.

@alexdowad
Copy link
Contributor

Hmm. "Laziness by default" is powerful (witness Haskell), but can be expensive when you don't actually need it.

@alexdowad
Copy link
Contributor

Another perspective: in Ruby 2.0, all Enumerables have a method called #lazy. This returns an instance of a class called Enumerator::Lazy. Lazy is itself Enumerable, and at least some of its methods are lazy; they also return instances of Lazy. When a Lazy needs to be converted to something "real", like an Array, only as much of the input as is needed is consumed.

The problem is that some of the methods of Lazy are... not lazy. They force the entire input to be processed as soon as they are called. #partition is an example. Hamster does better here.

If Ruby's Lazy was fully lazy, there would be little reason for Hamster's lazy lists to exist. What would remain would be the persistent data structures (which I think is really's Hamster's raison de etre).

Linked lists are still a useful (and functional, persistent) data structure to provide. Though it might make more sense to just make them strict, and use Ruby's built-in Lazy for lazy processing of input, when it is needed.

As the built-in lazy processing features of Ruby become more developed, methods like Hamster.iterate may or may not remain useful. It depends whether something equivalent is added to Ruby core or not.

I wouldn't want to make any drastic changes to Hamster::List right now. Though I think its lazy features should be deemphasized a bit when the documentation is written for the 1.0 release. Some things, like IO#to_list, might even be deprecated.

Opinions?

@krainboltgreene krainboltgreene modified the milestone: 1.1.0 Oct 25, 2014
@alexdowad
Copy link
Contributor

More thoughts: our lazy lists are far more efficient now than they original were. Will we actually gain any significant performance from making them strict? It would be interesting to benchmark and see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants