-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Applicative functor which collects all your fails -- @package applicative-fail @version 0.0.1 module Control.Applicative.Fail -- | Applicative functor which collects all the fails instead of immediate -- returning first fail like Either. It can not be a monad because -- of differenct logic in Applicative. Applicative instance of Fail -- continue to fold fails even when 'Fail e Nothing' pattern is met. -- Monad instance can not behave like that, so Fail have no Monad -- instance -- -- Example usage: -- --
-- >>> (,,) <$> Fail [10] (Just 10) <*> Success 10 <*> Success 20 -- Fail [10] (Just (10,10,20)) -- -- >>> (,) <$> Fail [1] Nothing <*> Success 10 -- Fail [1] Nothing -- -- >>> (,) <$> Fail [1] (Just 10) <*> Fail [2] (Just 20) -- Fail [1,2] (Just (10,20)) ---- -- or like that: -- --
-- >>> (,) <$> ffail "oups" <*> fsucc 10 -- Fail ["oups"] Nothing -- -- >>> (,,) <$> fwarn "oups" 10 <*> fwarn "meh" 20 <*> fsucc 30 -- Fail ["oups","meh"] (Just (10,20,30)) -- -- >>> (,,) <$> ffail "oups" <*> ffail "meh" <*> fsucc 30 -- Fail ["oups","meh"] Nothing ---- -- This type is usefull for form parsing and returning your own type of -- errors data Fail e a -- | (Just a) when checking may proceed in Applicative Fail :: e -> (Maybe a) -> Fail e a Success :: a -> Fail e a ffail :: e -> Fail [e] a fwarn :: e -> a -> Fail [e] a fsucc :: a -> Fail e a getFail :: Fail e a -> Maybe e getSucc :: Fail e a -> Maybe a failEither :: Fail e a -> Either e a mapFail :: (e -> e') -> Fail e a -> Fail e' a -- | Join two fails like monad does joinFail :: Monoid e => Fail e (Fail e a) -> Fail e a -- | This is a monadic-like bind. It breaks computation like Maybe and does -- not correspond to Applicative instance behaviour. So, instead of -- implementing Monad instance we just implement separate bind -- operator bindFail :: Monoid e => Fail e a -> (a -> Fail e b) -> Fail e b composeFail :: Monoid e => (a -> Fail e b) -> (b -> Fail e c) -> a -> Fail e c instance Typeable Fail instance (Eq e, Eq a) => Eq (Fail e a) instance (Ord e, Ord a) => Ord (Fail e a) instance (Show e, Show a) => Show (Fail e a) instance (Read e, Read a) => Read (Fail e a) instance Functor (Fail e) instance Foldable (Fail e) instance Traversable (Fail e) instance Generic (Fail e a) instance Datatype D1Fail instance Constructor C1_0Fail instance Constructor C1_1Fail instance (Monoid e, Monoid a) => Monoid (Fail e a) instance Monoid e => Applicative (Fail e)