Safe Haskell | None |
---|---|
Language | Haskell2010 |
Extensions |
|
Synopsis
- type Result = ResultT Identity
- pattern Result :: Either String a -> Result a
- runResult :: Result a -> Either String a
- pattern Error :: String -> Result a
- pattern Success :: a -> Result a
- result :: (String -> b) -> (a -> b) -> Result a -> b
- fromEither :: Either String a -> Result a
- toEither :: Result a -> Either String a
- fromSuccess :: a -> Result a -> a
- toMonadFail :: MonadFail m => Result a -> m a
- data ResultT m a
- pattern ResultT :: Functor m => m (Either String a) -> ResultT m a
- runResultT :: Functor m => ResultT m a -> m (Either String a)
- mapResultT :: (Functor m, Functor n) => (m (Either String a) -> n (Either String b)) -> ResultT m a -> ResultT n b
- throwE :: Monad m => String -> ResultT m a
- catchE :: Monad m => ResultT m a -> (String -> ResultT m a) -> ResultT m a
- liftCallCC :: CallCC m (Either String a) (Either String b) -> CallCC (ResultT m) a b
- liftListen :: Monad m => Listen w m (Either String a) -> Listen w (ResultT m) a
- liftPass :: Monad m => Pass w m (Either String a) -> Pass w (ResultT m) a
The Result monad
result :: (String -> b) -> (a -> b) -> Result a -> b Source #
Case analysis for the Result
type.
Examples
>>>
let s = Success 0
>>>
let e = Error "critical"
>>>
result ("Bad: " ++) (("OK: " ++) . show) s
"OK: 0">>>
result ("Bad: " ++) (("OK: " ++) . show) e
"Bad: critical"
fromSuccess :: a -> Result a -> a Source #
Convert
to Result
aa
with a default value.
The ResultT monad transformer
A monad transformer that is similar to ExceptT
except a MonadFail
instance.
MonadFail
=ResultT
.throwE
Instances
pattern ResultT :: Functor m => m (Either String a) -> ResultT m a Source #
Construct and destruct Result
.
mapResultT :: (Functor m, Functor n) => (m (Either String a) -> n (Either String b)) -> ResultT m a -> ResultT n b Source #
Map the unwrapped computation using the given function.
Exception operations
catchE :: Monad m => ResultT m a -> (String -> ResultT m a) -> ResultT m a Source #
Handle an exception.
Lifting other operations
liftCallCC :: CallCC m (Either String a) (Either String b) -> CallCC (ResultT m) a b Source #
Lift a callCC
operation to the new monad.
liftListen :: Monad m => Listen w m (Either String a) -> Listen w (ResultT m) a Source #
Lift a listen
operation to the new monad.
liftPass :: Monad m => Pass w m (Either String a) -> Pass w (ResultT m) a Source #
Lift a pass
operation to the new monad.