fantasyland / fantasy-land

Specification for interoperability of common algebraic structures in JavaScript
MIT License
10.11k stars 375 forks source link

[Question] Type signature for ap #298

Closed shineli1984 closed 6 years ago

shineli1984 commented 6 years ago

I had a look at a few fantasy-* repos where ap method is derived as below

SomeApplicative.prototype.ap = function(a) { return this.chain(f => a.map(f)) }

In the current ap type signature ap :: Apply f => f a ~> f (a -> b) -> f b, my understanding is that f a refers to this in the above method.

So I'm wondering if the type signature for ap should be:

ap :: Apply f => f (a -> b) ~> f a -> f b

?

Avaq commented 6 years ago

See also: https://github.com/fantasyland/fantasy-land/issues/169, https://github.com/fantasyland/fantasy-land/issues/181, https://github.com/fantasyland/fantasy-land/issues/228, https://github.com/fantasyland/fantasy-land/issues/242, and https://github.com/fantasyland/fantasy-land/issues/283.

How ptotoype.ap is implemented is up to library authors. Most of the time, it will be as ap :: Apply f => f (a -> b) ~> f a -> f b, because it favours readability when fluent-method chaining.

Fantasy land doesn't specify prototype.ap. It specifies prototype['fantasy-land/ap'], and that one is the other way around.

It was changed for reasons of consistency when Fantasy Land 1.0 was released. The fantasy-* repos were never updated to adopt the new prefixed method specifications.

shineli1984 commented 6 years ago

Thanks for the explaination.