exceptional-0.1.4.1: Essentially the Maybe type with error messages.

Safe HaskellSafe
LanguageHaskell98

Control.Exceptional

Synopsis

Documentation

data Exceptional x Source

This is basically specialized 'Either String', or Maybe with error messages.

Constructors

Failure String 
Success x 

runExceptional :: Monad m => Exceptional x -> m x Source

Convert Exceptional into another Monad. If you don't have proper exception handling in your monad, this can throw errors.

runExceptional (Failure s) = fail s
runExceptional (Success s) = pure s

fromMaybe :: String -> Maybe a -> Exceptional a Source

Convert a Maybe to an Exceptional

fromMaybe s Nothing = fail s
fromMaybe s (Just x) = pure x

toMaybe :: Exceptional a -> Maybe a Source

Convert an Exceptional into a Maybe. This function disregards the error message.

toMaybe (Success x) = Just x
toMaybe (Failure _) = Nothing

fromEither :: Either String a -> Exceptional a Source

Convert an Either String to an Exceptional

fromEither (Left s) = fail s
fromEither (Right x) = pure x

toEither :: Exceptional a -> Either String a Source

Convert an Exceptional to an Either String

toEither (Failure s) = Left s
toEither (Success x) = Right x