Skip to content
0:00 / 0:00

#mtl#monadtransformers#lens

Next Level MTL - George Wilson - BFPG 2016-06

Brisbane Functional Programming Group

710 subscribers • 6 videos on Hallway

YouTube
  • Recommended by 2 people: 1 in engineering communities and 1 curated list.
  • Presented by George Wilson

Advanced. Deep dive for people who know the field.

10K views11 years ago2 recommendations

Programming languagesSoftware designHaskellFunctional programmingDesign patterns

George Wilson demonstrates how to use the mtl and lens libraries in Haskell to decouple functions from concrete monad transformer stacks.

Many applications leverage monad transformer stacks to control IO effects, handle error conditions, pass configurations, and more. As the requirements of these applications grow, the complexity of these transformer stacks can grow proportionally. If a specific monad transformer stack is used in type signatures, then small changes to the stack can result in large changes to the code. This talk will demonstrate tools from the mtl and the lens library that allow each function's type to describe the required parts of a transformer stack, without depending on the concrete stack itself.

Why it's here

2 people recommend this

What people say. Recommended as a classic talk on managing monad transformer stacks using classy optics in Haskell.

Moments people linked to

u/GeorgeTalksCodein r/haskell • Recommends

"Next Level mtl with Classy Optics" by George Wilson at BFPG

programming-talkscurated list on GitHubRecommends

Under “Haskell”

Next Level MTL 00:44:36 by **George Wilson** (2015)

u/evanrelfcss wranglerin r/haskell • Mentions

On “What is your favorite video with Haskell”

Next Level MTL by George Wilson is good. link to this video

u/edwardkmettin r/haskell • Mentions

On “Monad transformers objections”

You don't tend to build up lots of layers with the MTL that grow uncontrollably. Build one 'reader' level and throw all your environment stuff into it, one 'state' level and throw the stuff you plan to change, maybe some kind of sum type for handling exceptional control flow and you have 90% of the MTL stacks out there. Then use lenses or whatever to help manage the fact that you are touching parts of a larger whole. link to this video If you're building up multiple readers or multiple states you are probably using it "wrong," as evidenced by the fact that you have to count off to your desired state manually with lifts in unary. I don't really follow where you see free monads as wrong though.

u/edwardkmettin r/haskell • Mentions

On “What is the type signature of AppT people usually use?”

…sy lens instances. So, for me, the usual type of `App` is just `m` with a pile of constraints on it as talked about by George here. In the cases where dispatch for the more polymorphic type signature becomes a performance bottleneck, I can always manifest a particular monad at the last second and define the embedding of it with something like link to this video…

u/n00bombin r/haskell • Mentions

On “Effectful”

You can learn about "classy MTL" from George Wilson's Next Level MTL. It helps you understand the scope and limitations of `MTL` while preparing you to use effect systems like `Effectful`.

u/Axman6in r/haskell • Mentions

On “What was the topmost thing you learned about Haskell in 2016?”

I think this is a good place, I learnt this directly from Tony: http://tonymorris.github.io/talks/#9ae5e0fa2e1b0db7589dc5398bab4b07dc971e21 Also this gist really made the idea strike home for me: https://gist.github.com/nkpart/c3bcb48c97c5ded6e277 Also, this talk by George Wilson is a pretty good introduction to both of these topics: link to this video

u/edwardkmettin r/haskell • Mentions

On “Recommended way to use monad transformers, MTL-style effects or alternatives”

…ore situations, e.g. before setup, or getting away with using parts of your type checking code in a much more limited context. That way if something needs backtracking, I can turn it on just beforehand, or propagate it out. This gives me a lot more control over the handling of my effects. George Wilson gave a pretty decent talk on this approach: link to this video…

u/edwardkmettin r/haskell • Mentions

On “Would it be safe to allow type synonym family application in instance heads when they're injective in all of the otherwise unconstrained type variables?”

There are at least 2-3 different mtl alternatives out there that allow you to use multiple reader instances. You just need to throw away the functional dependency, teach yourself to accept overlapping instances in your code without throwing up and realize that they all come at the low low price of not being able to infer types for them pretty much at all as the moment you go to access the environment with anything that is polymorphic in the argument, it'll just fail to reduce so you'll have to litter your code with explicit types. An alternative style of coding for the mtl that doesn't require these practices works off the shelf: link to this video

u/n00bombin r/haskell • Mentions

On “Books on software architecture”

Next Level MTL - George Wilson

u/hardwaresoftonin r/haskell • Mentions

Monad transformer stacks vs ReaderT Pattern Back when I started writing a very small web application, monad transformer stacks were the first solution I wrapped my head around (I say that very very loosely), so they're what I've been using up until now, but the polymorphic single-monad-stack that is the ReaderT Pattern (https://www.fpcomplete.com/blog/2017/06/readert-design-pattern) seems so much more convenient to me now. **I'm curious to know what people are using in production/hobby code**. Also, if you're wondering why I didn't mention Free monads, I drank the koolaid from the following two posts: - https://markkarpov.com/post/free-monad-considered-harmful.html - http://tech.frontrowe…

u/hardwaresoftonin r/haskell • Mentions

On “How I write REST-ish Services in Haskell: Part 1 (project setup + config wrangling)”

Part 2/3/4 should be way more broadly useful to haskellers, because I want to cover things like how I build components and how I use `mtl` style and the `ReaderT` pattern to make writing `servant` handlers easy and type-enhanced. If that stuff is more interesting to you I'd recommend these two talks: - Ben Kolera - Monad Transformers - Next Level MTL Thanks for reading!

u/erikdin r/haskell • Mentions

On “George Wilson - The Extended Functor Family [21:56]”

This is another really good presentation from George Wilson.

u/hardwaresoftonin r/haskell • Mentions

On “How I write REST-ish Services in Haskell: Part 2 (domain modeling)”

Hey sounds like you're going to be bored with part 3! I basically do that, but only use typeclasses on monads, without `lens`. I haven't actually fully grokked lenses/prisms/generic-lens yet (which is why I'm avoiding them), but George Wilson's talk on Classy Optics was huge to me (there's also one more talk by Ben Kolera which is relevant as well) . At that point I'd already been doing something similar but without `lens` (just stringing together accessors) and didn't feel too ashamed. I'm not sure which part you meant about why my approach is needed, but it's definitely *not*! I can justify *why* I wrote the article like I did: - The basic `Task` to show how - The `Task f` to be abl…

u/ChrisPennerin r/haskell • Mentions

On “How to Idiomatically write nested ADTs”

Check out the "classy prisms" pattern for this; it's typically used for combining many disparate error types into a larger "Errors" sum type, but would work for this situation as well. This video by George Wilson explains the classy prisms pattern: [video It's not exactly what you're asking for, but can help generate some of the annoying machinery for you; I'd recommend checking it out at least.
5View on Reddit

u/_jackdk_in r/haskell • Mentions

On “Dealing with big towers of monad transformers?”

Add in the technique from the talk Next Level MTL and you've got a stew.