Skip to content

Commit f19b538

Browse files
committed
clean up parser fmap
1 parent 9d0b57f commit f19b538

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

_chapters/haskell3.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ instance Functor Parser where
11191119
fmap f (Parser p) = Parser (\i -> ((f <$>) <$>) (p i))
11201120
```
11211121

1122-
This is now in the form `(f . g) i)` where `f` is equal to `((f <$>) <$>)` and g is equal to `p`. Therefore:
1122+
If we define `g=((f <$>) <$>)`, then we can rewrite the body of the lambda `g (p i)`, which is simply the composition of `g` and `p`. Therefore:
11231123

11241124
```haskell
11251125
instance Functor Parser where
@@ -1134,7 +1134,7 @@ instance Functor Parser where
11341134
```
11351135

11361136
**`fmap` over `Function`:**
1137-
The last thing we notice is that the `Functor` instance for functions is defined as compose. Therefore, we have finally reached the end of our journey and can rewrite this as follows.
1137+
As discussed [earlier](/haskell3/#Functor), the `Functor` instance for functions defines `fmap` of functions as their composition. Therefore, we have finally reached the end of our journey and can rewrite this as follows.
11381138

11391139
```haskell
11401140
-- >>> parse ((*2) <$> int) "123+456"
@@ -1143,7 +1143,7 @@ instance Functor Parser where
11431143
fmap f (Parser p) = Parser (((f <$>) <$>) <$> p)
11441144
```
11451145

1146-
The whacky triple-nested application of `<$>` comes about because the result type `a` in our `Parser` type is nested inside a Tuple (`(,a)`), nested inside a `Maybe`, nested inside a function (`->r`).
1146+
Thus, the whacky triple-nested application of `<$>` comes about because the result type `a` in our `Parser` type is nested inside a Tuple (`(,a)`), nested inside a `Maybe`, nested inside a function (`->r`) -- all of which are instances of Functor and can therefore be mapped over.
11471147

11481148
---
11491149

0 commit comments

Comments
 (0)