diff --git a/src/Toml/Schema/Matcher.hs b/src/Toml/Schema/Matcher.hs index 5dd8151..0f9f2e8 100644 --- a/src/Toml/Schema/Matcher.hs +++ b/src/Toml/Schema/Matcher.hs @@ -47,6 +47,7 @@ import Control.Applicative (Alternative(..)) import Control.Monad (MonadPlus, ap, liftM) import Data.Monoid (Endo(..)) import Data.Text (Text) +import Data.Bifunctor (Bifunctor (..)) -- | Computations that result in a 'Result' and which track a list -- of nested contexts to assist in generating warnings and error @@ -130,6 +131,14 @@ data Result e a Eq {- ^ Default instance -}, Ord {- ^ Default instance -}) +instance Functor (Result e) where + fmap _ (Failure e) = Failure e + fmap f (Success e a) = Success e (f a) + +instance Bifunctor Result where + bimap f _ (Failure e) = Failure (fmap f e) + bimap f g (Success e a) = Success (fmap f e) (g a) + -- | Run a 'Matcher' with an empty scope. runMatcher :: Matcher l a -> Result (MatchMessage l) a runMatcher (Matcher m) = m [] mempty (Failure . runDList) (Success . runDList)