@@ -224,11 +224,11 @@ programming patterns have a monadic structure: passing around
224
224
implicit data, or short-circuiting a chain of evaluations if one
225
225
fails, to choose but two.
226
226
227
- ** The Monad typeclass
227
+ ** The Monad type class
228
228
229
229
We can capture the notions of chaining and injection, and the
230
- types that we want them to have, in a Haskell typeclass . The
231
- standard ~Prelude~ already defines just such a typeclass , named
230
+ types that we want them to have, in a Haskell type class . The
231
+ standard ~Prelude~ already defines just such a type class , named
232
232
~Monad~.
233
233
234
234
#+BEGIN_SRC haskell
@@ -263,7 +263,7 @@ behavior to its name is that it /returns/ a pure value (of type
263
263
~a~) into a monad (of type ~m a~).
264
264
265
265
While ~(>>=)~ and ~return~ are the core functions of the ~Monad~
266
- typeclass , it also defines two other functions. The first is
266
+ type class , it also defines two other functions. The first is
267
267
~(>>)~. Like ~(>>=)~, it performs chaining, but it ignores the
268
268
value on the left.
269
269
@@ -367,10 +367,10 @@ familiar with. These aren't formal terms, but they're in common
367
367
use, so it's helpful to know about them.
368
368
369
369
- "Monadic" simply means "pertaining to monads". A monadic /type/
370
- is an instance of the ~Monad~ typeclass ; a monadic /value/ has a
370
+ is an instance of the ~Monad~ type class ; a monadic /value/ has a
371
371
monadic type.
372
372
- When we say that a type "is a monad", this is really a shorthand
373
- way of saying that it's an instance of the ~Monad~ typeclass .
373
+ way of saying that it's an instance of the ~Monad~ type class .
374
374
Being an instance of ~Monad~ gives us the necessary monadic
375
375
triple of type constructor, injection function, and chaining
376
376
function.
@@ -388,7 +388,7 @@ use, so it's helpful to know about them.
388
388
389
389
In our introduction to monads, we showed how some pre-existing
390
390
code was already monadic in form. Now that we are beginning to
391
- grasp what a monad is, and we've seen the ~Monad~ typeclass , let's
391
+ grasp what a monad is, and we've seen the ~Monad~ type class , let's
392
392
build a monad with foreknowledge of what we're doing. We'll start
393
393
out by defining its interface, then we'll put it to use. Once we
394
394
have those out of the way, we'll finally build it.
@@ -461,7 +461,7 @@ runLogger :: Logger a -> (a, Log)
461
461
462
462
*** Controlled escape
463
463
464
- The ~Monad~ typeclass doesn't provide any means for values to
464
+ The ~Monad~ type class doesn't provide any means for values to
465
465
escape their monadic shackles. We can inject a value into a monad
466
466
using ~return~. We can extract a value from a monad using ~(>>=)~
467
467
but the function on the right, which can see an unwrapped value,
@@ -658,7 +658,7 @@ functor, calling the function on it, and rewrapping the result
658
658
with the same constructor.
659
659
660
660
We do exactly the same thing with a monad. Because the ~Monad~
661
- typeclass already provides the ~(>>=)~ and ~return~ functions that
661
+ type class already provides the ~(>>=)~ and ~return~ functions that
662
662
know how to unwrap and wrap a value, the ~liftM~ function doesn't
663
663
need to know any details of a monad's implementation.
664
664
@@ -670,7 +670,7 @@ liftM f m = m >>= \i ->
670
670
#+END_SRC
671
671
672
672
When we declare a type to be an instance of the ~Functor~
673
- typeclass , we have to write our own version of ~fmap~ specially
673
+ type class , we have to write our own version of ~fmap~ specially
674
674
tailored to that type. By contrast, ~liftM~ doesn't need to know
675
675
anything of a monad's internals, because they're abstracted by
676
676
~(>>=)~ and ~return~. We only need to write it once, with the
@@ -849,7 +849,7 @@ flavours, each with different levels of strictness.
849
849
Our ~Logger~ monad is a specialised version of the standard
850
850
~Writer~ monad, which can be found in the ~Control.Monad.Writer~
851
851
module of the ~mtl~ package. We will present a ~Writer~ example in
852
- [[file:16-programming-with-monads.org::*Using typeclasses ][the section called "Using typeclasses "]]
852
+ [[file:16-programming-with-monads.org::*Using type classes ][the section called "Using type classes "]]
853
853
854
854
** The Maybe monad
855
855
@@ -1631,14 +1631,14 @@ rand = getStdRandom (randomR (0, maxBound))
1631
1631
(The ~randomR~ function takes an inclusive range within which the
1632
1632
generated random value should lie.)
1633
1633
1634
- The ~System.Random~ module provides a typeclass , ~RandomGen~, that
1634
+ The ~System.Random~ module provides a type class , ~RandomGen~, that
1635
1635
lets us define new sources of random ~Int~ values. The type
1636
1636
~StdGen~ is the standard ~RandomGen~ instance. It generates
1637
1637
pseudorandom values. If we had an external source of truly random
1638
1638
data, we could make it an instance of ~RandomGen~ and get truly
1639
1639
random, instead of merely pseudorandom, values.
1640
1640
1641
- Another typeclass , ~Random~, indicates how to generate random
1641
+ Another type class , ~Random~, indicates how to generate random
1642
1642
values of a particular type. The module defines ~Random~ instances
1643
1643
for all of the usual simple types.
1644
1644
@@ -1882,7 +1882,7 @@ conventionally named ~join~.
1882
1882
If we had definitions of ~join~ and ~fmap~, we wouldn't need to
1883
1883
write a definition of ~(>>=)~ for every monad, because it would be
1884
1884
completely generic. Here's what an alternative definition of the
1885
- ~Monad~ typeclass might look like, along with a definition of
1885
+ ~Monad~ type class might look like, along with a definition of
1886
1886
~(>>=)~.
1887
1887
1888
1888
#+BEGIN_SRC haskell
0 commit comments