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.
ExceptTwhen we want to combine the approach in (1) on top on an existing type with monadic capabilities.
- Using exceptions for IO code.
We've also learned a few new abstractions and techniques:
Traversabletype class, for data structures that can be traversed from left to right such as linked lists, binary trees and
Maps. Pretty useful when combined with another applicative functor type like
Monadtype class extends the
Applicativetype class with the
join :: m (m a) -> m afunction. We learned that
Eitherimplements this type class interface and so does
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 an
Either-like monad transformer,
ExceptT, on top of
We are almost done. Only a couple more things left to do with this project. Let's go!