note and hush for #22

This commit is contained in:
Stephen Diehl
2016-10-10 11:13:26 +01:00
parent 2010cec78e
commit 7a0e274b20
3 changed files with 30 additions and 0 deletions
+1
View File
@@ -46,6 +46,7 @@ library
Functor
Semiring
Bifunctor
Exceptions
Panic
other-modules:
+28
View File
@@ -0,0 +1,28 @@
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Exceptions (
hush,
note,
tryIO,
) where
import Base (IO)
import Data.Function ((.))
import Control.Monad.Trans (liftIO)
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.Except (ExceptT(..), MonadError, throwError)
import Control.Exception as Exception
import Control.Applicative
import Data.Maybe (Maybe, maybe)
import Data.Either (Either(..))
hush :: Alternative m => Either e a -> m a
hush (Left _) = empty
hush (Right x) = pure x
note :: (MonadError e m) => e -> Maybe a -> m a
note err = maybe (throwError err) pure
tryIO :: MonadIO m => IO a -> ExceptT IOException m a
tryIO = ExceptT . liftIO . Exception.try
+1
View File
@@ -35,6 +35,7 @@ import Either as X
import Applicative as X
import Conv as X
import Panic as X
import Exceptions as X
import Base as Base hiding (
putStr -- Overriden by Show.putStr