note and hush for #22
This commit is contained in:
@@ -46,6 +46,7 @@ library
|
||||
Functor
|
||||
Semiring
|
||||
Bifunctor
|
||||
Exceptions
|
||||
Panic
|
||||
|
||||
other-modules:
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user