Are there any good examples of Functor
s which are not Applicative
s? By good, I'm seeking non-trivial (not Const Void
) examples which don't need appeals to undefined
. If there are none is there any method of proving that the space there is uninteresting?
This is similar to Good examples of Not a Functor/Functor/Applicative/Monad?, but it wasn't completely resolved there.
As a follow-up question, are there any interesting examples of Functor
s which might be left without Applicative
instances due to having far too many non-canonical Applicative
instances to be meaningful? For instance, "extended Maybe
" is a bit boring
data MayB a = Jus a | Nothing1 | Nothing2 | Nothing3 | ...
instance Applicative MayB where
pure = Jus
Jus f <*> Jus x = Jus (f x)
Jus f <*> n = n
n <*> Jus x = n
n1 <*> n2 = methodOfResolvingNothingWhatsoever n1 n2
Are there examples where the variations of the Applicative
instance are more material?
data MayB a = Jus a | Nothin Int
andNothin n1 <*> Nothin n2 = Nothin $ max n1 n2
is how I'd implement it. Then you have a notion of the level of failure where the higher level takes precedence. Not sure where this is useful, but it's easy to encode. – bheklilrCont m
is an applicative iffm
is a monoid so there's a lot of functors-not-applicatives there. Essentially anything with a lot of "structure" unrelated to the parameter which we've defined functor over is going to have a hard time being an applicative. – Daniel Gratzerdata Eit b a = L b | R a
withinstance Monoid b => Applicative (Either b) where L b1 <*> L b2 = L (b1 <> b2)
. Generally, though, there are just a whole lot of ways to merge failures and "purely applicative Either" is the closest thing I know to a canonical method. – J. AbrahamsonFunctor
typeclass and not just anApplicative
one that includesfmap
. – J. Abrahamson(a -> m) -> m
can be given anApplicative
instance (modulo wrapping it in anewtype
) for anym
that has an associative binary operation with an identity, not just ones that happen to have been given aMonoid
instance. – Tom Ellis