We can have two types f, g :: * -> * such that they're not monads, but their composition is. For example for an arbitrary fixed s:
f a := s -> a
g a := (s, a)
g a isn't a monad (unless we restrict s to a monoid), but f (g a) is the state monad s -> (s, a). (Unlike functors and applicative functors, even if both f and g were monads, their composition might not be.)
Is there a similar example for functors or applicative functors? That is that the composition of f and g is a a functor (or an applicative functor), even though
- one of
fandgisn't an (applicative) functor and the other is, or - neither of them is an (applicative) functor,
ContTtransformer makesFunctors andApplicatives without requiring that the transformed structure is aFunctor, but isn't built by composition. hackage.haskell.org/package/transformers-0.4.1.0/docs/… Similarly, the free applicativeApaddsApplicativebehavior to anyFunctor, without requiring that it beApplicative, but again isn't built by composition. hackage.haskell.org/package/free-4.9/docs/… - CirdecFandGare adjoint you get a monad in the composition. - Philip JF