Skip to content
0:00 / 0:00

#monadtransformers#lenses#profunctors

Edward Kmett - Monad Transformer Lenses

Monadic Warsaw

1K subscribers • 8 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Edward Kmett

Advanced. Deep dive for people who know the field.

7.4K views10 years ago2 recommendations

Programming languagesSoftware designHaskellFunctional programmingPerformance and optimization

Edward Kmett discusses building a monoidal category of monad transformers and using lenses on this category to produce highly efficient Haskell code.

I'll talk a bit about how we can do lenses in much more general settings. Then, given that the venue is "Monadic Warsaw" I'll show how we can build a monoidal category of monad transformers and work with lenses on this category with an eye towards how this can let us produce much more efficient code than we can with just the MTL classes as we know them today. No real prior exposure to lenses is required, and all talk of profunctors and the like should be self-contained, but some basic understanding of monad transformers would be helpful.

Why it's here

2 people recommend this

What people say. Recommended as an advanced exploration of monad transformers and optics for performance optimization.

Moments people linked to

u/b4zzl3in r/haskell • Recommends

Edward Kmett - Monad Transformer Lenses

u/gozesin r/haskell • Recommends

Monad Transformer Lenses

u/tomejaguarin r/haskell • Mentions

Monad transformer optics Yesterday I asked a question about a certain form of commutation operation for monad transformers. I've followed it a bit further and (re)discovered that you can make optics for monad transformers. See the source file on my GitHub account for full details, but as a taster, ``` type a ~> b = forall r . a r -> b r type LensLike f s (t :: * -> *) a b = (a ~> f b) -> (s ~> f t) type ASetter s t a b = (a ~> IdentityT b) -> (s ~> IdentityT t) lensIdentity :: (MFunctor t, Monad a, Monad b) => (a ~> t b) -> (IdentityT a ~> t (IdentityT b)) affineState :: (MonadTrans t, MFunctor t, Monad (t (StateT s b)), Monad a, Monad b) => LensLike t (StateT s a) (StateT…

u/edwardkmettin r/haskell • Mentions

On “Typeclass Lenses”

> I wonder if you could do something cool with monad transformers though. link to this video directly tackles this, and the follow up link to this video takes it in a slightly different direction.

u/Faucelmein r/haskell • Mentions

On “Edward Kmett - Monad Transformer Lenses”

It is mentioned near link to this video that the MTL has performance problems with recursion. Does the Rank n' Classy approach face the same problems?
3View on Reddit

u/edwardkmettin r/haskell • Mentions

On “Using (functor) profunctor optics to alleviate the n × m instances problem in MTL”

I gave a talk on them at Monadic Warsaw at some point, before I pivoted and gave a talk on monad monomorphisms at Zurihac a couple weeks later.

u/edwardkmettin r/haskell • Mentions

On “Converting `ReaderT ctx (ExceptT e IO) a` to `ReaderT ctx IO (Either e a)`”

Control.Monad.Morph is missing a superclass constraint of the form class (forall m. Monad m => Monad (t m)) => MFunctor t where on `MFunctor`. which bites you in the ass later on and forbids some complex instances from being written. `monadology` includes it (admittedly, through a rather circuitous encoding) in its equivalent. https://hackage.haskell.org/package/monadology-0.1/docs/Control-Monad-Ology-General-Trans-Hoist.html#t:MonadTransHoist IIRC, this old talk of mine: link to this video goes into why this constraint is a good idea to require.