Skip to content

Unfoldable.generate #11

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

Closed
wants to merge 1 commit into from
Closed

Conversation

matthewleon
Copy link
Contributor

Construct an Unfoldable by applying a function to an incremented index.

Construct an Unfoldable by applying a function to an incremented index.
@paf31
Copy link
Contributor

paf31 commented Dec 3, 2017

Isn't this the same as map f [0..] in Haskell. Maybe the simplest thing would be to just export nats :: Unfoldable f => f Int

@matthewleon
Copy link
Contributor Author

This PR avoids creating an ephemeral data structure to map over. I imagine that GHC is smart enough to stop that from happening, but we will be unfolding strict data structures in PureScript (and the lazy lists we do have retain a reference to the head).

That said, exporting nats seems like a reasonable idea as well.

@paf31
Copy link
Contributor

paf31 commented Dec 4, 2017

I think there are a lot of cases where we could do map fusion on behalf of the compiler, in libraries, but I don't think we should. If someone needs fusion to happen enough, they can write the definition inline in a where clause, right? The core libraries shouldn't do everything, just enough, in my opinion at least.

@matthewleon
Copy link
Contributor Author

Sounds reasonable. I'll get around to a PR for nats soon then.

@matthewleon matthewleon closed this Dec 4, 2017
@matthewleon
Copy link
Contributor Author

Now that I reconsider, though, the issue with exporting nats is that it only works on lazy structures. I guess that's the issue for me... Either we do fusion ourselves, or the function won't terminate.

Am I overlooking a simple solution?

@matthewleon matthewleon reopened this Dec 4, 2017
@paf31
Copy link
Contributor

paf31 commented Dec 4, 2017

In that case, I think what we need is a range function.

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