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
Eithertype to encode "a value or an error". Useful approach for uneffectful code - Using
ExceptTwhen 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
Traversabletype class, for data structures that can be traversed from left to right, such as linked lists, binary trees andMaps. Pretty useful when combined with another applicative functor type likeEitherorIO - The
Monadtype class extends theApplicativetype class with thejoin :: m (m a) -> m afunction. We learned thatEitherimplements this type class interface, and so doesIO - The
MonadTranstype 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.