Skip to content

Conversation

rgrempel
Copy link
Contributor

@rgrempel rgrempel commented Jan 6, 2016

The unfoldableList implementation wasn't tail-recursive, which caused the problems described here:

hdgarrood/purescript-sequences#20

This pull request changes unfoldr so that it is tail-recursive. The provided test fails without the change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to be reversed?

@rgrempel
Copy link
Contributor Author

rgrempel commented Jan 6, 2016

Yes, I just noticed that too! I'll work on a fix.

@rgrempel
Copy link
Contributor Author

rgrempel commented Jan 6, 2016

I've added the call to reverse, and I squashed the commits.

I wasn't sure whether the right thing to do was reverse the whole thing at the end (which is what I chose), or try to add each individual item to the end as we go. If the latter is better, I'd be happy to do that instead.

@rgrempel
Copy link
Contributor Author

rgrempel commented Jan 6, 2016

I took a look at Data.List.snoc, and it seems clear that it is better to build up the list backwards and then reverse it at the end (as this PR now does) -- otherwise, one would be reversing and re-reversing a lot!

paf31 added a commit that referenced this pull request Jan 6, 2016
Make unfoldr stack-safe.
@paf31 paf31 merged commit 39ab01e into purescript:master Jan 6, 2016
@paf31
Copy link
Contributor

paf31 commented Jan 6, 2016

👍 Thanks!

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.

2 participants