explicit-exception 0.1.2 → 0.1.3
raw patch · 2 files changed
+28/−5 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Monad.Exception.Synchronous: assert :: e -> Bool -> Exceptional e ()
+ Control.Monad.Exception.Synchronous: assertT :: (Monad m) => e -> Bool -> ExceptionalT e m ()
+ Control.Monad.Exception.Synchronous: switch :: (e -> b) -> (a -> b) -> Exceptional e a -> b
+ Control.Monad.Exception.Synchronous: toMaybe :: Exceptional e a -> Maybe a
Files
explicit-exception.cabal view
@@ -1,5 +1,5 @@ Name: explicit-exception-Version: 0.1.2+Version: 0.1.3 License: BSD3 License-File: LICENSE Author: Henning Thielemann <haskell@henning-thielemann.de>@@ -21,9 +21,9 @@ Handling of the first one is called \"exception handling\", whereas handling of errors is better known as \"debugging\". .- For an application see the @midi@ package.+ For applications see the packages @midi@, @spreadsheet@, @http-monad@. .- Although I'm not happy with the identifier style of the Monad Template Library+ Although I'm not happy with the identifier style of the Monad Transformer Library (partially intended for unqualified use) I have tried to adopt it for this library, in order to let Haskell programmers get accustomed easily to it.@@ -46,7 +46,7 @@ Source-Repository this type: darcs location: http://code.haskell.org/explicit-exception/- tag: 0.1.2+ tag: 0.1.3 Library Build-Depends: base >= 2, transformers >=0.0 && <0.2
src/Control/Monad/Exception/Synchronous.hs view
@@ -4,13 +4,15 @@ -} module Control.Monad.Exception.Synchronous ( Exceptional(..),- fromMaybe,+ fromMaybe, toMaybe, fromEither, toEither, getExceptionNull,+ switch, force, mapException, mapExceptional, throw,+ assert, catch, resolve, @@ -21,6 +23,7 @@ mapExceptionT, mapExceptionalT, throwT,+ assertT, catchT, bracketT, resolveT,@@ -58,6 +61,9 @@ fromEither :: Either e a -> Exceptional e a fromEither = either Exception Success +toMaybe :: Exceptional e a -> Maybe a+toMaybe = switch (const Nothing) Just+ toEither :: Exceptional e a -> Either e a toEither x = case x of@@ -73,6 +79,15 @@ {- |+Counterpart to 'either' for 'Either'.+-}+switch :: (e -> b) -> (a -> b) -> Exceptional e a -> b+switch f g x =+ case x of+ Success a -> g a+ Exception e -> f e++{- | If you are sure that the value is always a 'Success' you can tell that the run-time system thus making your program lazy.@@ -97,6 +112,10 @@ throw :: e -> Exceptional e a throw = Exception +assert :: e -> Bool -> Exceptional e ()+assert e b =+ if b then Success () else throw e+ catch :: Exceptional e0 a -> (e0 -> Exceptional e1 a) -> Exceptional e1 a catch x handler = case x of@@ -204,6 +223,10 @@ throwT :: (Monad m) => e -> ExceptionalT e m a throwT = ExceptionalT . return . throw++assertT :: (Monad m) =>+ e -> Bool -> ExceptionalT e m ()+assertT e = ExceptionalT . return . assert e catchT :: (Monad m) => ExceptionalT e0 m a ->