diff --git a/src/Control/Monad/Logic/Trans.purs b/src/Control/Monad/Logic/Trans.purs index 763441a..d1ed097 100644 --- a/src/Control/Monad/Logic/Trans.purs +++ b/src/Control/Monad/Logic/Trans.purs @@ -1,9 +1,9 @@ -module Control.Monad.Logic.Trans (SFKT, runSFKT) where +module Control.Monad.Logic.Trans (SFKT, runSFKT, runSFKTOnce) where import Prelude (class Applicative, class Apply, class Bind, class Functor, class Monad, bind, pure, ($), (<<<), (>>=)) import Control.Monad.Logic.Class -import Control.MonadPlus (class MonadPlus, class Alternative, class Alt, class Plus, (<|>)) +import Control.MonadPlus (class MonadPlus, class Alternative, class Alt, class Plus, (<|>), empty) import Control.Monad.Reader.Class (class MonadReader, local, class MonadAsk, ask) import Control.Monad.State.Class (class MonadState, state) import Control.Monad.Trans.Class (class MonadTrans, lift) @@ -27,6 +27,9 @@ unSFKT (SFKT f) = f runSFKT :: forall a m. Applicative m => SFKT m a -> m (List a) runSFKT (SFKT f) = f (map <<< (:)) (pure Nil) +runSFKTOnce :: forall a m. MonadPlus m => SFKT m a -> m a +runSFKTOnce (SFKT f) = f ((<|>) <<< pure) empty + instance Functor (SFKT m) where map f m = SFKT (\sk -> unSFKT m (\a -> sk (f a)))