Make once really only run once

This commit is contained in:
Danila Fedorin 2023-03-04 21:47:41 -08:00
parent 2facde2377
commit 1a2f69036c

View File

@ -1,6 +1,6 @@
module Control.Monad.Logic.Trans (SFKT, runSFKT, runSFKTOnce) where
import Prelude (class Applicative, class Apply, class Bind, class Functor, class Monad, bind, pure, ($), (<<<), (>>=))
import Prelude (class Applicative, class Apply, class Bind, class Functor, class Monad, bind, pure, ($), (<<<), (>>=), const)
import Control.Monad.Logic.Class
import Control.MonadPlus (class MonadPlus, class Alternative, class Alt, class Plus, (<|>), empty)
@ -24,11 +24,11 @@ newtype SFKT m a = SFKT (forall ans. SK (m ans) a -> FK (m ans) -> m ans)
unSFKT :: forall a m. SFKT m a -> forall ans. SK (m ans) a -> FK (m ans) -> m ans
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. Alternative m => SFKT m a -> m a
runSFKTOnce (SFKT f) = f ((<|>) <<< pure) empty
runSFKTOnce (SFKT f) = f (const <<< pure) empty
runSFKT :: forall a m. Monad m => SFKT m a -> m (List a)
runSFKT (SFKT f) = f (map <<< (:)) (pure Nil)
instance Functor (SFKT m) where
map f m = SFKT (\sk -> unSFKT m (\a -> sk (f a)))