Is there a monad that doesn't have a corresponding monad transformer (except IO)?

前端 未结 4 577
离开以前
离开以前 2020-12-02 11:54

So far, every monad (that can be represented as a data type) that I have encountered had a corresponding monad transformer, or could have one. Is there such a monad that can

4条回答
  •  失恋的感觉
    2020-12-02 12:41

    My solution exploits the logical structure of Haskell terms etc.

    I looked at right Kan extensions as possible representations of the monad transformer. As everyone knows, right Kan extensions are limits, so it makes sense that they should serve as universal encoding of any object of interest. For monadic functors F and M, I looked at the right Kan extension of MF along F.

    First I proved a lemma, "rolling lemma:" a procomposed functor to the Right kan extension can be rolled inside it, giving the map F(Ran G H) -> Ran G(FH) for any functors F, G, and H.

    Using this lemma, I computed a monadic join for the right Kan extension Ran F (MF), requiring the distributive law FM -> MF. It is as follows:

    Ran F(MF) . Ran F(MF) [rolling lemma] =>
      Ran F(Ran F(MF)MF) [insert eta] =>
      Ran F(Ran F(MF)FMF) [gran] =>
      Ran F(MFMF) [apply distributive law] =>
      Ran F(MMFF) [join Ms and Fs] =>
      Ran F(MF).
    

    What seems to be interesting about this construction is that it admits of lifts of both functors F and M as follows:

    (1) F [lift into codensity monad] =>
      Ran F F [procompose with eta] =>
      Ran F(MF).
    
    (2) M [Yoneda lemma specialized upon F-] =>
      Ran F(MF).
    

    I also investigated the right Kan extension Ran F(FM). It seems to be a little better behaved achieving monadicity without appeal to the distributive law, but much pickier in what functors it lifts. I determined that it will lift monadic functors under the following conditions:

    1) F is monadic.

    2) F |- U, in which case it admits the lift F ~> Ran U(UM). This can be used in the context of a state monad to "set" the state.

    3) M under certain conditions, for instance when M admits a distributive law.

提交回复
热议问题