-
Notifications
You must be signed in to change notification settings - Fork 23
add nats: natural numbers for lazy unfoldable #12
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
Conversation
src/Data/Unfoldable.purs
Outdated
@@ -88,6 +89,13 @@ none = unfoldr (const Nothing) unit | |||
singleton :: forall f a. Unfoldable f => a -> f a | |||
singleton = replicate 1 | |||
|
|||
-- | Produce a Lazy Unfoldable structure representing the natural numbers. | |||
nats :: forall f a. Unfoldable f => Semiring a => Lazy (f a) => f a | |||
nats = defer \_ -> unfoldr increment zero |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need defer
here, since any lazy structure should use it anyway. Did you try this on lazy lists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. Will fix.
@@ -18,7 +18,8 @@ | |||
], | |||
"dependencies": { | |||
"purescript-partial": "^1.2.0", | |||
"purescript-tuples": "^4.0.0" | |||
"purescript-tuples": "^4.0.0", | |||
"purescript-control": "^3.3.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this any more, right?
src/Data/Unfoldable.purs
Outdated
@@ -88,6 +89,13 @@ none = unfoldr (const Nothing) unit | |||
singleton :: forall f a. Unfoldable f => a -> f a | |||
singleton = replicate 1 | |||
|
|||
-- | Produce a Lazy Unfoldable structure representing the natural numbers. | |||
nats :: forall f a. Unfoldable f => Semiring a => Lazy (f a) => f a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f
might be lazy but in the wrong way. I think we need a comment to say that the result is actually infinite.
done
…On Sun, Dec 10, 2017 at 6:45 PM, Phil Freeman ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/Data/Unfoldable.purs
<#12 (comment)>
:
> @@ -88,6 +89,13 @@ none = unfoldr (const Nothing) unit
singleton :: forall f a. Unfoldable f => a -> f a
singleton = replicate 1
+-- | Produce a Lazy Unfoldable structure representing the natural numbers.
+nats :: forall f a. Unfoldable f => Semiring a => Lazy (f a) => f a
f might be lazy but in the wrong way. I think we need a comment to say
that the result is actually infinite.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#12 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARBS_j8t9nZUVDrtCkIjfe34rZglR8Rks5s_G0NgaJpZM4Q1cF4>
.
|
Can we generalise this to |
Good call. |
A couple nitpicks I've noticed which are no longer relevant if we are generalising to |
following conversation here: #11
This adds a dependency.
I've tested the laziness here: https://github.com/matthewleon/purescript-lists/tree/test-nats