Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #24 from zerobuzz/update-docs-for-except

Update docs for except
  • Loading branch information...
commit 6407d6df3107f5b58029a5b46da80dc122d97988 2 parents 9a7e72f + 2a9a02f
@ekmett authored
Showing with 9 additions and 12 deletions.
  1. +4 −2 Control/Monad/Error/Class.hs
  2. +5 −10 Control/Monad/Except.hs
View
6 Control/Monad/Error/Class.hs
@@ -79,8 +79,10 @@ In that case and many other common cases the resulting monad is already defined
as an instance of the 'MonadError' class.
You can also define your own error type and\/or use a monad type constructor
other than @'Either' 'String'@ or @'Either' 'IOError'@.
-In these cases you will have to explicitly define instances of the 'Error'
-and\/or 'MonadError' classes.
+In these cases you will have to explicitly define instances of the 'MonadError'
+class.
+(If you are using the deprecated "Control.Monad.Error" or
+"Control.Monad.Trans.Error", you may also have to define an 'Error' instance.)
-}
class (Monad m) => MonadError e m | m -> e where
-- | Is used within a monadic computation to begin exception processing.
View
15 Control/Monad/Except.hs
@@ -99,18 +99,13 @@ or a string longer than 5 characters. Otherwise it prints length of the string.
> s <- getLine
> reportResult (calculateLength s)
>
->-- Wraps length calculation to catch the errors.
->-- Returns either length of the string or an error.
->calculateLength :: String -> LengthMonad Int
->calculateLength s = (calculateLengthOrFail s) `catchError` Left
->
>-- Attempts to calculate length and throws an error if the provided string is
>-- empty or longer than 5 characters.
->-- The processing is done in Either monad.
->calculateLengthOrFail :: String -> LengthMonad Int
->calculateLengthOrFail [] = throwError EmptyString
->calculateLengthOrFail s | len > 5 = throwError (StringTooLong len)
-> | otherwise = return len
+>-- (Throwing an error in this monad means returning a 'Left'.)
+>calculateLength :: String -> LengthMonad Int
+>calculateLength [] = throwError EmptyString
+>calculateLength s | len > 5 = throwError (StringTooLong len)
+> | otherwise = return len
> where len = length s
>
>-- Prints result of the string length calculation.
Please sign in to comment.
Something went wrong with that request. Please try again.