module Data.Vinyl.Idiom.Validation where
import Data.Vinyl.Idiom.Identity
import Data.Vinyl.Functor
import Control.Applicative
import Data.Monoid
data Result e a
= Failure e
| Success a
deriving (Show, Eq)
type Validator e = Lift (->) Identity (Result e)
instance Functor (Result e) where
fmap f (Success x) = Success $ f x
fmap _ (Failure e) = Failure e
instance Monoid e => Applicative (Result e) where
pure = Success
(Success f) <*> (Success x) = Success $ f x
(Failure e) <*> (Success _) = Failure e
(Success _) <*> (Failure e) = Failure e
(Failure e) <*> (Failure e') = Failure $ e <> e'