hsmisc-1.2: A collection of miscellaneous modules

Safe HaskellSafe
LanguageHaskell98

HsMisc.Control.Monad.Except

Description

Convenience function for turning (Maybe a) values into (MonadError e a) actions plus a function for expressing Data.Map lookups as MonadError actions

Synopsis

Documentation

maybeThrow :: MonadError e m => e -> Maybe a -> m a Source

Turn an error value and a (Maybe a) into a (MonadError e a) action

lookupEWith :: (MonadError e m, Ord k) => (k -> e) -> k -> Map k a -> m a Source

Look up a String key in a Map as an action in (MonadError e), providing a function to transform key type k to error type e.

See lookupE below for a usage example.

lookupE :: (Ord k, Show k, MonadError String m) => k -> Map k a -> m a Source

Look up a key in a Map as an action in (MonadError String), with a default message that the key was not found as the error.