From ed6fa9c8ea8cf1e2f358667c6a42ea410fb867fb Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Wed, 14 Dec 2016 17:16:20 +0000 Subject: [PATCH] refine monaderror section --- docs/Exceptions.md | 50 ++++++++++++++++++++++++++++++++++++++-------- src/Protolude.hs | 2 +- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/docs/Exceptions.md b/docs/Exceptions.md index 88bd82f89..a5a1f137a 100644 --- a/docs/Exceptions.md +++ b/docs/Exceptions.md @@ -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 ``` diff --git a/src/Protolude.hs b/src/Protolude.hs index d9c990949..eccb878cf 100644 --- a/src/Protolude.hs +++ b/src/Protolude.hs @@ -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)