Skip to content
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

should Chain properties depends on fantasy-land/ap (and possibly .map)? #334

Open
bunglegrind opened this issue Feb 11, 2023 · 4 comments
Open

Comments

@bunglegrind
Copy link

bunglegrind commented Feb 11, 2023

It's more like a question than an actual issue:

Since Chain must implement the Apply specification, I'm expecting that one of the Chain properties should depends on something related to the Apply properties (as, for instance, Applicative's fantasy-land/of properties resort to the fantasy-land/ap method).

@Avaq
Copy link
Contributor

Avaq commented Feb 15, 2023

In my personal (contested) view it does, but not as explicitly. The dependency is captured in the Derivations section of the spec, where a relationship between ap and chain is described:

fantasy-land/ap may be derived from fantasy-land/chain:

function ap(m) { return m['fantasy-land/chain'](f => this['fantasy-land/map'](f)); }

I read this as: "A Chain must implement chain such that ap may be derived from it, and therefore every Chain has ap (is an extension of Apply), and ap must behave as if derived from chain".

EDIT: Another way to think of it is that the Apply interface is like a weaker Chain interface: Apply can be defined in terms of Chain, but not the other way around. Since Apply is a weak Chain, Chain is an extended Apply. So we have the arrow Apply -> Chain come out naturally.

@bunglegrind
Copy link
Author

Well, the derivation section uses the "may" expression, not the "must". IMHO, an explicit property should be added to the fantasy-land/chain method, which should enfasize the relationship between fantasy-land/ap and fantasy-land/chain (and, possibly, fantasy-land/map). Otherwise, Chain should be placed at the same level of Functor

@Avaq
Copy link
Contributor

Avaq commented Feb 16, 2023

I agree with you. I think the "may"-expression in the derivations section is a source of confusion. It's using "may" to suggest that a developer doesn't have to derive their implementation of ap from their implementation of chain, but "may" choose do so.

The reason they "may" choose to do so, is because it is assumed (but never explicitly stated) that this is always possible. I think the spec should be updated to make this more clear.

Furthermore, it is never made clear whether the non-derived implementation of ap must behave in exactly the same way as the version derived from chain would have, but in my view it should. This is the view that's contested (as far as I know, also in the broader FP community).


I've seen this discussion play out in other threads on this repo as well. A quick search came up with #214 but I think there might be more.

@bunglegrind
Copy link
Author

I see. If I look through all the definitions I find other examples (traversable, for instance). Anyway, I'll follow your suggestion: I'll consider the derivation section mandatory. 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

No branches or pull requests

2 participants