Skip to content

Commit d7833f4

Browse files
Remove outdated explanation regarding Monad/Applicative class hierarchy (#149)
Signed-off-by: Xingye-Dujing <63134338+Xingye-Dujing@users.noreply.github.com> Co-authored-by: Matthijs <19817960+MatthijsBlom@users.noreply.github.com>
1 parent 073efb7 commit d7833f4

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

source_md/a-fistful-of-monads.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Wow, who would have thought?
208208
This is what the type class looks like:
209209

210210
```{.haskell:hs}
211-
class Monad m where
211+
class Applicative m => Monad m where
212212
return :: a -> m a
213213
214214
(>>=) :: m a -> (a -> m b) -> m b
@@ -222,13 +222,6 @@ class Monad m where
222222

223223
![this is you on monads](assets/images/a-fistful-of-monads/kid.png){.right width=363 height=451}
224224

225-
Let's start with the first line.
226-
It says `class Monad m where`.
227-
But wait, didn't we say that monads are just beefed up applicative functors?
228-
Shouldn't there be a class constraint in there along the lines of `class (Applicative m) => Monad m where` so that a type has to be an applicative functor first before it can be made a monad?
229-
Well, there should, but when Haskell was made, it hadn't occurred to people that applicative functors are a good fit for Haskell so they weren't in there.
230-
But rest assured, every monad is an applicative functor, even if the `Monad` class declaration doesn't say so.
231-
232225
The first function that the `Monad` type class defines is `return`.
233226
It's the same as `pure`, only with a different name.
234227
Its type is `(Monad m) => a -> m a`.

source_md/for-a-few-monads-more.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ Finally, we introduced monads as improved applicative functors, which added the
11751175

11761176
So every monad is an applicative functor and every applicative functor is a functor.
11771177
The `Applicative` type class has a class constraint such that our type has to be an instance of `Functor` before we can make it an instance of `Applicative`.
1178-
But even though `Monad` should have the same constraint for `Applicative`, as every monad is an applicative functor, it doesn't, because the `Monad` type class was introduced to Haskell way before `Applicative`.
1178+
Likewise, the `Monad` class enforces an `Applicative` constraint, ensuring every monad instance is strictly built upon an applicative functor instance.
11791179

11801180
But even though every monad is a functor, we don't have to rely on it having a `Functor` instance because of the `liftM` function.
11811181
`liftM` takes a function and a monadic value and maps it over the monadic value.

0 commit comments

Comments
 (0)