Open bunglegrind opened 1 year ago
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.
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
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 https://github.com/fantasyland/fantasy-land/issues/214 but I think there might be more.
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!
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 thefantasy-land/ap
method).