refine monaderror section
This commit is contained in:
+42
-8
@@ -1,7 +1,8 @@
|
|||||||
Exceptions
|
Exceptions
|
||||||
==========
|
==========
|
||||||
|
|
||||||
#### MonadError
|
MonadError
|
||||||
|
----------
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
class Monad m => MonadError e (m :: * -> *) | m -> e where
|
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
|
catchError :: m a -> (e -> m a) -> m a
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Except
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
type Except e = ExceptT e Identity
|
type Except e = ExceptT e Identity
|
||||||
```
|
```
|
||||||
|
|
||||||
|
*Example*:
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
```
|
||||||
|
|
||||||
|
#### ExceptT
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
newtype ExceptT e (m :: * -> *) a
|
newtype ExceptT e (m :: * -> *) a
|
||||||
= Control.Monad.Trans.Except.ExceptT (m (Either e a))
|
= Control.Monad.Trans.Except.ExceptT (m (Either e a))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
*Example*:
|
||||||
|
|
||||||
|
```haskell
|
||||||
|
```
|
||||||
|
|
||||||
|
#### throwError
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
throwError :: MonadError e m => e -> m a
|
throwError :: MonadError e m => e -> m a
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### catchError
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
catchError :: MonadError e m => m a -> (e -> m a) -> m a
|
catchError :: MonadError e m => m a -> (e -> m a) -> m a
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### runExcept
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
runExcept :: Except e a -> Either e a
|
runExcept :: Except e a -> Either e a
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### runExceptT
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
runExceptT :: ExceptT e m a -> m (Either e a)
|
runExceptT :: ExceptT e m a -> m (Either e a)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Exceptions
|
Exceptions
|
||||||
|
----------
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
class (Typeable e, Show e) => Exception e where
|
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
|
GHC.Exception.displayException :: e -> String
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### throwIO
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
throwIO :: (MonadIO m, Exception e) => e -> m a
|
throwIO :: (MonadIO m, Exception e) => e -> m a
|
||||||
```
|
```
|
||||||
|
|
||||||
```haskell
|
#### throwSTM
|
||||||
throwTo :: (MonadIO m, Exception e) => ThreadId -> e -> m ()
|
|
||||||
```
|
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
throwSTM :: Exception e => e -> STM a
|
throwSTM :: Exception e => e -> STM a
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### throwTo
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
throwError :: MonadError e m => e -> m a
|
throwTo :: (MonadIO m, Exception e) => ThreadId -> e -> m ()
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Utilities
|
Utilities
|
||||||
|
---------
|
||||||
|
|
||||||
|
#### hush
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
hush :: Alternative m => Either e a -> m a
|
hush :: Alternative m => Either e a -> m a
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### note
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
note :: (MonadError e m, Applicative m) => e -> Maybe a -> m a
|
note :: (MonadError e m, Applicative m) => e -> Maybe a -> m a
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### tryIO
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
tryIO :: MonadIO m => IO a -> ExceptT IOException m a
|
tryIO :: MonadIO m => IO a -> ExceptT IOException m a
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Fatal Errors
|
Fatal Errors
|
||||||
|
------------
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
data FatalError = FatalError {msg :: Text}
|
data FatalError = FatalError {msg :: Text}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### panic
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
panic :: Text -> a
|
panic :: Text -> a
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user