on master help sign in
Briefly correct ExceptT mentions into Handler (#693)
commit29f94a64408d6a7815dbe43fd06e8b372b3230e9 authorOleg Grenrus <oleg.grenrus@iki.fi> dateMon 30 Jan 2017, 15:45 (10 years ago) parent2fd9757
1 file changed+8−9
doc/tutorial/Server.lhs+8−9
doc/tutorial/Server.lhs+8−9
@@ -603,8 +603,8 @@ $ curl -H 'Accept: text/html' http://localhost:8081/persons
603603
604604## The `Handler` monad
605605
606−At the heart of the handlers is the monad they run in, namely `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`.
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)).
608608One might wonder: why this monad? The answer is that it is the
609609simplest monad with the following properties:
610610
@@ -626,7 +626,7 @@ action that either returns an error or a result.
626626
627627The module [`Control.Monad.Except`](https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Except.html#t:ExceptT)
628628from 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
630630`throwError` can be used to return an error from your handler (whereas `return`
631631 is enough to return a success).
632632
@@ -636,8 +636,8 @@ kind and abort early. The next two sections cover how to do just that.
636636
637637### Performing IO
638638
639−Another important instance from the list above is `MonadIO m => MonadIO
640−(ExceptT e m)`.
639+Another important instances from the list above are `MonadIO m => MonadIO
640+(ExceptT e m)`, and therefore also `MonadIO Handler` as there is `MonadIO IO` instance..
641641[`MonadIO`](http://hackage.haskell.org/package/transformers-0.4.3.0/docs/Control-Monad-IO-Class.html)
642642is a class from the **transformers** package defined as:
643643
@@ -646,8 +646,7 @@ class Monad m => MonadIO m where
646646 liftIO :: IO a -> m a
647647```
648648
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
651650IO computation in your handlers, just use `liftIO`:
652651
653652``` haskell
@@ -861,7 +860,7 @@ Server UserAPI4 = Int -> ( Handler User
861860
862861In the first case, each handler receives the *userid* argument. In the latter,
863862the 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:
865864
866865``` haskell
867866server8 :: Server UserAPI3
@@ -1069,7 +1068,7 @@ readerToHandler :: Reader String :~> Handler
10691068
10701069Let's start with `readerToHandler'`. We obviously have to run the `Reader`
10711070computation 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
10731072that function with the `NT` constructor to make it have the fancier type.
10741073
10751074``` haskell