-
Notifications
You must be signed in to change notification settings - Fork 376
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
update Extend and Comonad dependencies to match figure #213
Conversation
👍
…On Fri, 16 Dec 2016, 23:15 David Chambers, ***@***.***> wrote:
Thank you for pointing out this inconsistency, @jlmorgan
<https://github.com/jlmorgan>.
If Extend really *does* depend on Functor we should update the
description of Extend rather than merge this pull request.
------------------------------
You can view, comment on, or merge this pull request online at:
#213
Commit Summary
- figures: remove Functor -> Extend from dependency graph
File Changes
- *M* README.md
<https://github.com/fantasyland/fantasy-land/pull/213/files#diff-0>
(2)
- *M* figures/dependencies.dot
<https://github.com/fantasyland/fantasy-land/pull/213/files#diff-1>
(1)
- *M* figures/dependencies.png
<https://github.com/fantasyland/fantasy-land/pull/213/files#diff-2>
(0)
Patch Links:
- https://github.com/fantasyland/fantasy-land/pull/213.patch
- https://github.com/fantasyland/fantasy-land/pull/213.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#213>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACcaGDRfO34m_Y_5a5TtVAm3-9thMX4Kks5rIxufgaJpZM4LPrsp>
.
|
But shouldn't Comonad depend on Functor? Spec says so. |
Thanks, @rpominov! I've updated the pull request. :) |
That's instructive, @safareli. Shall we revert the changes to the diagram and instead move the reference to the Functor dependency in the spec from Comonad to Extend? |
|
Yeah, we do want |
3638c56
to
5fade48
Compare
@@ -28,7 +28,7 @@ structures: | |||
* [Bifunctor](#bifunctor) | |||
* [Profunctor](#profunctor) | |||
|
|||
<img src="figures/dependencies.png" width="888" height="340" /> | |||
<img src="figures/dependencies.png" width="888" height="347" /> |
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 is now an unrelated—but still intentional—change.
Please have another look, @joneshf. |
Hmm, good question. Maybe we don't need it. Though, then I wonder if we need |
Is there a way to implement chain(f) { return this.map(f).join(); }
join() { return this.value; } Seems like you can't since |
@joneshf I don't think we should drop extend f = fmap f . duplicate if we substitute extend f = fmap f . extend id |
@jlmorgan Sure. extend(f) { return this.duplicate().map(f); }
duplicate() { return F(this); } @safareli That law is only needed if you're defining both FWIW, I've found defining |
Maybe a worthwhile law is the second one here under fmap (fmap f) . extend id = extend id . fmap f Maybe that's just a free theorem? |
Don't know but nor in or we can just move the |
Could someone propose appropriate names for the Extend and Comonad laws? When we moved a law from Comonad to Extend we ended up with two Extend laws both described as "associativity". |
That law is not even in cats CoflatMap. I think we should just remove it, and if we in future have some way in the spec to say that for example Extend should define |
Shouldn't everything that derives from e.extend(a => a) is equivalent to e (identity)
e.extend(x => f(g(x))) is equivalent to e.extend(g).extend(f) (composition) You could add in e.extend(f).extend(g) is equivalent to e.extend(x => f(x).extend(g)) (associativity) Personally, I think having the companion functions like Edit: After some testing with the following method setup: class Thing {
constructor(v) { this.value = v; }
map(f) { return new Thing(f(this.value)); }
join() { return this.value; }
chain(f) { return this.map(f).join(); }
duplicate() { return new Thing(this); }
extend(f) { return this.duplicate().map(f); }
toString() { return `[${this.constructor.name} ${this.value}]`; }
}
const compose = f => g => x => f(g(x));
const id = x => x;
const e = new Thing(1);
const f = id;
const g = id;
console.log(
"identity",
e.extend(id).toString(),
"should equal",
e.toString()
);
console.log(
"composition",
e.extend(compose(f)(g)).toString(),
"should equal",
e.extend(f).extend(g).toString()
);
console.log(
"associativity",
e.extend(f).extend(g).toString(),
"should equal",
e.extend(x => f(x).extend(g)).toString()
); I get the following:
Associativity definitely worked. = ) This is likely due to my lack of understanding. 😆 Edit 2:
With the companion methods, it seems more like I just need |
It's coherence: https://github.com/typelevel/cats/blob/155f7f534993c30d6e757de990330ac796dad5da/laws/src/main/scala/cats/laws/CoflatMapLaws.scala#L19-L20
Sounds good to me. |
@jlmorgan "identity" and "composition" as you've defined them there should not work, as you've shown. If they did work, then |
This commit also removes the third Comonad law.
@joneshf the "coherence" uses |
@safareli I'm confused. What are we talking about? |
What i'm saying is that the |
Shall we merge this pull request, @joneshf? |
😂
…On Tue, 20 Dec 2016, 20:01 David Chambers, ***@***.***> wrote:
Shall we merge this pull request, @joneshf <https://github.com/joneshf>?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#213 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACcaGDPH6hho5lcOSqBM4KAvYuwaYf6vks5rKDQqgaJpZM4LPrsp>
.
|
Thank you for pointing out this inconsistency, @jlmorgan.
If Extend really does depend on Functor we should update the description of Extend rather than merge this pull request.