• @demesisx
    link
    English
    113 months ago

    On the latest Haskell interlude podcast, the guest was talking about how using the ReaderT monad specifically introduces safety issues. My ears perked up because I’m right in the middle of leaning on it heavily in one of my Haskell projects.

    • John
      link
      fedilink
      33 months ago

      @demesisx @lysdexic No safety issues mentioned around ReaderT. The speaker was talking about how stacking monad transformers mtl-style can generate unnecessary closures that GHC can’t optimise away.

      • @demesisx
        link
        English
        103 months ago

        Thanks for the clarification.

  • @Corbin@programming.dev
    link
    fedilink
    English
    13 months ago

    I’ve recently come to appreciate monads as 2-arrows from the terminal object in a 2-category; quoting nLab:

    … a monad in [a category] K is a lax 2-functor from the terminal bicategory 1 to K: the unique object * of 1 is sent to the object a, the morphism 1 becomes [the endomorphism] t, and [the unit] η and [the join] μ arise from the coherent 2-cells expressing lax functoriality.

    This is a nifty demystification of the data of a monad. Why do endofunctors tend to carry monads? Because endofunctors on categories C tend to be expressible as endomorphisms in 2-categories where C is an object! Since this latter condition is typically trivial, it follows that endofunctors on C typically carry monads (and that any counterexamples depend on the structure of C and choice of 2-category.)