1
1
mirror of https://github.com/github/semantic.git synced 2024-12-19 21:01:35 +03:00

Define a MonadError instance for Amb.

This commit is contained in:
Rob Rix 2017-08-03 17:04:47 -04:00
parent 5ca85ec4ed
commit 9572b96fa4

View File

@ -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