A brief intro to MTL / Jappie

submited by
Style Pass
2021-08-10 11:30:05

Recently a blog post came out which I quite like, it describes how to use the concrete base transformers. It’s very thorough and gives a concrete example for using transformers. Although it looks quite low level and I think you’ll get more out of transformers by using full MTL .

That blogpost inspired me to write this, because I can’t find a succinct description on how to use MTL 1. I learned MTL by staring at reflex for days, if not weeks. Which is an uncomfortable learning process. To make MTL more accessible I’ll give a brief overview of this style3. I’ll write down how MTL works from the ground up, so people can read how to use it rather then struggling with code for days like I did.

We start by introducing m. Which could’ve been named monad or x, but the community settled on using m for type variables with the Monad constraint, so I will use this too. Normally we use type variable’s in concrete types, for example Maybe a or [a]. However, Instead of having our type variable inside a concrete type, we can also flip it around:

This compiles because the Monad constraint on m gives us the return function 2. After you’re convinced this is a valid definition, let’s use it. What can we do with this moreMonad binding? Well, we can pattern match on it:

Leave a Comment
Related Posts