In Maybe applicative, <*>
can be implemented based on fmap
. Is it incidental, or can it be generalized to other applicative(s)?
(<*>) :: Maybe (a -> b) -> Maybe a -> Maybe b
Nothing <*> _ = Nothing
(Just g) <*> mx = fmap g mx
Thanks.
See also In applicative, how can `<*>` be represented in terms of `fmap_i, i=0,1,2,...`?
It cannot be generalized. A
Functor
instance is unique:but there can be multiple valid
Applicative
instances for the same type constructor.In the latter, we neither want to apply any single function from the left argument to all elements of the right, nor apply all the functions on the left to any single element on the right, making
fmap
useless.