Two well-known examples of applicatives are monads and ziplists. Are there any other examples?
From Time flies like an applicative functor by Conor McBride:
Structure cops will note that
Deis another example of an applicative functor which is not a monad — join would bring things from the far future to the near future, and that had better not be possible. However, where applicative functors in general only pull through traversable functors (containers with finitely many elements),Depulls through all containers. So it’s a bit special. I wonder what it is.
and
The
Defunctor represents a fixed delay, rather than an arbitrary one. I’m dividing time into discrete slices.De xis the type of anxdue at the next slice.De (De x)is thus the type of anxdue in two slices’ time, and you can’t make it turn up any sooner!
Read the whole post. To answer the immediate question, the author’s conclusion is
Don’t Look!
OK, here’s the implementation. It’s a con.
newtype De x = De x deriving Show -- ssh, don't tell! instance Functor De where fmap f (De x) = De (f x) instance Applicative De where pure = De De f <*> De s = De (f s) fix :: (De x -> x) -> x fix f = f (De (fix f))