From 9572b96fa49adfe63f5e0644a6a75bd143c3c5bd Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 3 Aug 2017 17:04:47 -0400 Subject: [PATCH] Define a MonadError instance for Amb. --- src/Data/Amb.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Data/Amb.hs b/src/Data/Amb.hs index 3026dfadf..c3e479aa5 100644 --- a/src/Data/Amb.hs +++ b/src/Data/Amb.hs @@ -1,5 +1,7 @@ +{-# LANGUAGE MultiParamTypeClasses #-} module Data.Amb where +import Control.Monad.Error.Class import Data.List.NonEmpty import Data.Semigroup @@ -23,3 +25,8 @@ instance Monad (Amb l) where return = pure None a >>= _ = None a Some as >>= f = foldr1 (<>) (f <$> as) + +instance MonadError l (Amb l) where + throwError = None + None a `catchError` f = f a + Some as `catchError` _ = Some as