Summary
This was quite a section. Let's recount the things we've learned.
We discussed several ways to handle errors in Haskell:
- Encoding errors as a data type and using the
Either
type to encode "a value or an error". Useful approach for uneffectful code - Using
ExceptT
when we want to combine the approach in (1) on top of an existing type with monadic capabilities - Using exceptions for IO code
We've also learned a few new abstractions and techniques:
- The
Traversable
type class, for data structures that can be traversed from left to right, such as linked lists, binary trees andMap
s. Pretty useful when combined with another applicative functor type likeEither
orIO
- The
Monad
type class extends theApplicative
type class with thejoin :: m (m a) -> m a
function. We learned thatEither
implements this type class interface, and so doesIO
- The
MonadTrans
type class for monad transformers for types that take other monads as inputs and provide a monadic interface (>>=
, do notation, etc.) while combining both their capabilities. We saw how to stack anEither
-like monad transformer,ExceptT
, on top ofIO
We are almost done – only a couple more things left to do with this project. Let's go!
You can view the git commit of the changes we've made and the code up until now.