refine monaderror section

This commit is contained in:
Stephen Diehl
2016-12-14 17:16:20 +00:00
parent 1f2ed3e4cb
commit ed6fa9c8ea
2 changed files with 43 additions and 9 deletions
+42 -8
View File
@@ -1,7 +1,8 @@
Exceptions
==========
#### MonadError
MonadError
----------
```haskell
class Monad m => MonadError e (m :: * -> *) | m -> e where
@@ -9,34 +10,55 @@ class Monad m => MonadError e (m :: * -> *) | m -> e where
catchError :: m a -> (e -> m a) -> m a
```
#### Except
```haskell
type Except e = ExceptT e Identity
```
*Example*:
```haskell
```
#### ExceptT
```haskell
newtype ExceptT e (m :: * -> *) a
= Control.Monad.Trans.Except.ExceptT (m (Either e a))
```
*Example*:
```haskell
```
#### throwError
```haskell
throwError :: MonadError e m => e -> m a
```
#### catchError
```haskell
catchError :: MonadError e m => m a -> (e -> m a) -> m a
```
#### runExcept
```haskell
runExcept :: Except e a -> Either e a
```
#### runExceptT
```haskell
runExceptT :: ExceptT e m a -> m (Either e a)
```
#### Exceptions
Exceptions
----------
```haskell
class (Typeable e, Show e) => Exception e where
@@ -45,42 +67,54 @@ class (Typeable e, Show e) => Exception e where
GHC.Exception.displayException :: e -> String
```
#### throwIO
```haskell
throwIO :: (MonadIO m, Exception e) => e -> m a
```
```haskell
throwTo :: (MonadIO m, Exception e) => ThreadId -> e -> m ()
```
#### throwSTM
```haskell
throwSTM :: Exception e => e -> STM a
```
#### throwTo
```haskell
throwError :: MonadError e m => e -> m a
throwTo :: (MonadIO m, Exception e) => ThreadId -> e -> m ()
```
#### Utilities
Utilities
---------
#### hush
```haskell
hush :: Alternative m => Either e a -> m a
```
#### note
```haskell
note :: (MonadError e m, Applicative m) => e -> Maybe a -> m a
```
#### tryIO
```haskell
tryIO :: MonadIO m => IO a -> ExceptT IOException m a
```
#### Fatal Errors
Fatal Errors
------------
```haskell
data FatalError = FatalError {msg :: Text}
```
#### panic
```haskell
panic :: Text -> a
```
+1 -1
View File
@@ -426,7 +426,7 @@ map :: Functor f => (a -> b) -> f a -> f b
map = fmap
uncons :: [a] -> Maybe (a, [a])
uncons [] = Nothing
uncons [] = Nothing
uncons (x:xs) = Just (x, xs)
unsnoc :: [x] -> Maybe ([x],x)