July 2023
Intermediate to advanced
670 pages
17h 13m
English
Before we dive into what we can do with Monad, let’s start by writing out our instance. You might recall that the Monad type class requires that we implement two functions: return and (>>=). When you already have an Applicative instance, like we do, it’s usually to define return in terms of pure. So, we’ll start by defining our new class:
| | instance Monad FilePackParser where |
| | return = pure |
Next we need to define (>>=). As you may recall, the general type of (>>=) is:
| | (>>=) :: m a -> (a -> m b) -> m b |
Or, specialized to FilePackParser:
| | (>>=) :: FilePackParser a -> (a -> FilePackParser b) -> FilePackParser b |
We’ll start out defining a new FilePackParser and binding its input so that we can use it inside ...
Read now
Unlock full access