@@ -603,8 +603,8 @@ $ curl -H 'Accept: text/html' http://localhost:8081/persons
604## The `Handler` monad
604## The `Handler` monad
606−At the heart of the handlers is the monad they run in, namely `ExceptT ServantErr IO`
606+At the heart of the handlers is the monad they run in, namely a newtype `Handler` around `ExceptT ServantErr IO`
607−([haddock documentation for `ExceptT`](http://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Except.html#t:ExceptT)), which is aliased as `Handler`.
607+([haddock documentation for `ExceptT`](http://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Except.html#t:ExceptT)).
608One might wonder: why this monad? The answer is that it is the
608One might wonder: why this monad? The answer is that it is the
609simplest monad with the following properties:
609simplest monad with the following properties:
@@ -626,7 +626,7 @@ action that either returns an error or a result.
627The module [`Control.Monad.Except`](https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Except.html#t:ExceptT)
627The module [`Control.Monad.Except`](https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Except.html#t:ExceptT)
628from which `ExceptT` comes is worth looking at.
628from which `ExceptT` comes is worth looking at.
629−Perhaps most importantly, `ExceptT` is an instance of `MonadError`, so
629+Perhaps most importantly, `ExceptT` and `Handler` are an instances of `MonadError`, so
630`throwError` can be used to return an error from your handler (whereas `return`
630`throwError` can be used to return an error from your handler (whereas `return`
631 is enough to return a success).
631 is enough to return a success).
@@ -636,8 +636,8 @@ kind and abort early. The next two sections cover how to do just that.
637### Performing IO
637### Performing IO
639−Another important instance from the list above is `MonadIO m => MonadIO
639+Another important instances from the list above are `MonadIO m => MonadIO
640−(ExceptT e m)`.
640+(ExceptT e m)`, and therefore also `MonadIO Handler` as there is `MonadIO IO` instance..
641[`MonadIO`](http://hackage.haskell.org/package/transformers-0.4.3.0/docs/Control-Monad-IO-Class.html)
641[`MonadIO`](http://hackage.haskell.org/package/transformers-0.4.3.0/docs/Control-Monad-IO-Class.html)
642is a class from the **transformers** package defined as:
642is a class from the **transformers** package defined as:
@@ -646,8 +646,7 @@ class Monad m => MonadIO m where
646 liftIO :: IO a -> m a
646 liftIO :: IO a -> m a
649−The `IO` monad provides a `MonadIO` instance. Hence for any type
650−`e`, `ExceptT e IO` has a `MonadIO` instance. So if you want to run any kind of
649+So if you want to run any kind of
651IO computation in your handlers, just use `liftIO`:
650IO computation in your handlers, just use `liftIO`:
653``` haskell
652``` haskell
@@ -861,7 +860,7 @@ Server UserAPI4 = Int -> ( Handler User
862In the first case, each handler receives the *userid* argument. In the latter,
861In the first case, each handler receives the *userid* argument. In the latter,
863the whole `Server` takes the *userid* and has handlers that are just
862the whole `Server` takes the *userid* and has handlers that are just
864−computations in `ExceptT`, with no arguments. In other words:
863+computations in `Handler`, with no arguments. In other words:
866``` haskell
865``` haskell
867server8 :: Server UserAPI3
866server8 :: Server UserAPI3
@@ -1069,7 +1068,7 @@ readerToHandler :: Reader String :~> Handler
1070Let's start with `readerToHandler'`. We obviously have to run the `Reader`
1069Let's start with `readerToHandler'`. We obviously have to run the `Reader`
1071computation by supplying it with a `String`, like `"hi"`. We get an `a` out
1070computation by supplying it with a `String`, like `"hi"`. We get an `a` out
1072−from that and can then just `return` it into `ExceptT`. We can then just wrap
1071+from that and can then just `return` it into `Handler`. We can then just wrap
1073that function with the `NT` constructor to make it have the fancier type.
1072that function with the `NT` constructor to make it have the fancier type.
1075``` haskell
1074``` haskell