Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can two non-functors compose to a functor?

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

  1. one of f and g isn't an (applicative) functor and the other is, or
  2. neither of them is an (applicative) functor,
like image 534
Petr Avatar asked Sep 21 '14 10:09

Petr


2 Answers

This is not a (covariant) functor

f x = x -> r

but f . f is the "continuation" functor (also a monad):

f (f x) = (x -> r) -> r

This is probably not the best example because f is a contravariant functor.

like image 107
chi Avatar answered Oct 15 '22 07:10

chi


Let g :: *->*. Then Const A . g is a functor for any A, in fact isomorphic to Const A.

like image 42
leftaroundabout Avatar answered Oct 15 '22 08:10

leftaroundabout