Permalink
Browse files

ExceptT

  • Loading branch information...
mlang committed Jan 9, 2019
1 parent 90293fe commit 5ad0315b44fc22c0416827cf175572606d56cf4a
Showing with 7 additions and 0 deletions.
  1. +7 −0 src/Control/Monad/Logic/Class.purs
@@ -2,12 +2,14 @@ module Control.Monad.Logic.Class where

import Prelude (class Monad, class Monoid, Unit, const, map, mempty, pure, unit, (<<<), ($), (#), (<#>), (>>=))
import Control.Apply (lift2)
import Control.Monad.Except.Trans (ExceptT(..))
import Control.Monad.Reader.Trans (ReaderT(..))
import Control.Monad.State.Trans (StateT(..))
import Control.Monad.Trans.Class (lift)
import Control.Monad.Writer.Trans (WriterT(..))
import Control.Plus (class Plus, empty, (<|>))
import Data.Array ((:), uncons)
import Data.Either (Either(..))
import Data.Maybe (Maybe(..), maybe)
import Data.Machine.Mealy (MealyT)
import Data.Machine.Mealy (interleave, msplit) as Mealy
@@ -40,6 +42,11 @@ instance monadLogicArray :: MonadLogic Array where
interleave xs ys = uncons xs # maybe ys \{head, tail} ->
head : interleave ys tail

instance monadLogicExceptT :: (Monoid e, MonadLogic m) => MonadLogic (ExceptT e m) where
msplit (ExceptT m) = ExceptT $ msplit m <#> maybe
(Right Nothing) \(Tuple a m') -> map (\x -> Just (Tuple x (ExceptT m'))) a
interleave (ExceptT m1) (ExceptT m2) = ExceptT $ m1 `interleave` m2

instance monadLogicMealyT :: Monad f => MonadLogic (MealyT f s) where
msplit = Mealy.msplit
interleave = Mealy.interleave

0 comments on commit 5ad0315

Please sign in to comment.