Skip to content

Conversation

@ibara1454
Copy link
Contributor

@ibara1454 ibara1454 commented Jan 3, 2018

A solution of #140

Here's the result of the modification of iterate.
All the values are evaluated exactly once.

fix_iterate

It still has a bug. Because the result of take 3 lazyl should be

> take 3 lazyl
1
2
fromStrict ((Cons 0 (Cons 1 (Cons 2 Nil))))

Not

> take 3 lazyl
1
2
3
fromStrict ((Cons 0 (Cons 1 (Cons 2 Nil))))

But the bug is made by take (as #138), not iterate. So we have nothing to do with this.

Just to be sure, I made a performance comparison between the before and after of iterate.
It is made by compiling the purescript code into javascript, and then run the benchmark by Benchmark.js.

Each value in this benchmark is the time of the calculation sum $ take n $ iterate (_ + 1) 1, where n is the length of list in the benchmark.

The old iterate has no value after length > 5000, because it throws exceptions by maximum call stack size exceeded. Yes, it is not stack-safe.

iterate

The old iterate run extremely slow in PSCi (time complexity is not linear), but (I don't know why) it is not bad (except the stack overflow) in this benchmark.

@ibara1454
Copy link
Contributor Author

The bug is based on fix.

@ibara1454 ibara1454 closed this Jan 8, 2018
@ibara1454 ibara1454 deleted the issue140 branch August 13, 2018 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant