Lax monoidal functors with a different monoidal structure

前端 未结 3 2125
陌清茗
陌清茗 2020-12-24 13:20

Applicative functors are well-known and well-loved among Haskellers, for their ability to apply functions in an effectful context.

In category-theoretic terms, it ca

3条回答
  •  死守一世寂寞
    2020-12-24 13:48

    Before you can even talk about monoidal functors, you need to make sure you're in a monoidal category. It so happens that Hask is a monoidal category in the following way:

    • () as identity
    • (,) as bifunctor
    • Identify isomorphic types, i.e. (a,()) ≅ ((),a) ≅ a, and (a,(b,c)) ≅ ((a,b),c).

    Like you observed, it's also a monoidal category when you exchange () for Void and (,) for Either.
    However, monoidal doesn't get you very far – what makes Hask so powerful is that it's cartesian closed. That gives us currying and related techniques, without which applicative would be pretty much useless.

    A monoidal category can be cartesian closed iff its identity is a terminal object, i.e. a type onto which there exists precisely one (of course, we disregard ⟂ here) arrow. There is one function A -> () for any type A, namely const (). There is no function A -> Void however. Instead, Void is the initial object: there exists precisely one arrow from it, namely the absurd :: Void -> a method. Such a monoidal category can't be cartesian closed then.
    Now, of course, you can switch between initial and terminal easily by turning around the arrow direction. That always places you in the dual structure, so we get a cocartesian closed category. But that means you also need to flip the arrows in your monoidal functors. Those are called decisive functors then (and generalise comonads). With Conor's ever-so-amazing naming scheme,

    class (Functor f) => Decisive f where
      nogood :: f Void -> Void
      orwell :: f (Either s t) -> Either (f s) (f t)
    

提交回复
热议问题