-
Notifications
You must be signed in to change notification settings - Fork 26
Lazy Cofree constructor #92
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
* Adds a `Lazy` instance. * Adds `buildCofree` which unfolds a label and subtree together.
Should probably fix |
src/Control/Comonad/Cofree.purs
Outdated
Cofree (e s) (defer \_ -> unfoldCofree e n <$> n s) | ||
Cofree (defer \_ -> Tuple (e s) (unfoldCofree e n <$> n s)) | ||
|
||
buildCofree |
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.
It doesn't look like this is used, and it looks like a duplicate of unfoldCofree
essentially. Is the idea just to save an extra allocation?
I would like to have only one, and deprecate the unfoldCofree
if we decide to keep this.
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.
The problem with unfoldCofree
is that the label and the functor are calculated independently, so they cannot share work. buildCofree
supersedes unfoldCofree
.
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.
Yeah, I'm happy to go with buildCofree
, although it really is the natural unfold, of course, so I would prefer if we could use the name unfoldCofree
. I suggest just adding a note that unfoldCofree
will be replaced by buildCofree
in a future release, please.
src/Control/Comonad/Cofree.purs
Outdated
|
||
-- | Lazily creates a value of type `Cofree f a` from a label and a | ||
-- | functor-full of "subtrees". | ||
liftC :: forall f a. (Unit -> Tuple a (f (Cofree f a))) -> Cofree 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.
This seems like a slightly unclear choice of name when we already have mkCofree
. I would prefer to be more explicit and call it something like mkCofreeLazy
but I'm open to other ideas.
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.
Yeah, I was just being consistent with liftF
, which is an equally unclear name. Happy to change it to whatever.
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 agree we should change both. My open PR calls it liftFree
actually, and moves it into a class.
src/Control/Comonad/Cofree.purs
Outdated
liftC :: forall f a. (Unit -> Tuple a (f (Cofree f a))) -> Cofree f a | ||
liftC = Cofree <<< defer | ||
deferCofree :: forall f a. (Unit -> Tuple a (f (Cofree f a))) -> Cofree f a | ||
deferCofree = Cofree <<< defer |
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've called this deferCofree
since it's just a specialized implementation of the Lazy
instance.
Great, thanks! |
Lazy
instance.buildCofree
which unfolds a label and subtree together.