module Err where data E e a = Failure e | Success a deriving Show unitE :: a -> E e a unitE a = Success a bindE :: E e a -> (a -> E e b) -> E e b (Success a) `bindE` k = k a (Failure e) `bindE` k = Failure e failE :: e -> E e a failE e = Failure e tryE :: E e a -> (e -> E e a) -> E e a tryE (Success v) h = Success v tryE (Failure e) h = h e