The ap() method in Apply isn't correct, but seems inverted.
it should be
ap :: Apply f => f a ~> f (a -> b) -> f b
Since the f (a -> b) should be the same of f a it's possible to implement the right method.
This is an example of the Identity monad:
/**
* @template T
*/
class Identity
{
/**
* @template U
* @template C as callable(T): U
*
* @param FantasyLand\Apply<C> $applicative
* @return FantasyLand\Apply<U>
*/
public function ap2(FantasyLand\Apply $applicative): FantasyLand\Apply
{
if (! $applicative instanceof self) {
throw new \LogicException(sprintf('Applicative must be an instance of %s', self::class));
}
return $applicative->bind(function (callable $f) {
return self::of($f($this->value));
});
}
}
The
ap()
method inApply
isn't correct, but seems inverted.it should be
Since the
f (a -> b)
should be the same off a
it's possible to implement the right method. This is an example of the Identity monad:In this way it's statically correct too.
This is a BC, so a new 2.0 version is necessary.