-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A backtracking logic-programming monad. -- -- A continuation-based, backtracking, logic programming monad. An -- adaptation of the two-continuation implementation found in the paper -- <a>Backtracking, Interleaving, and Terminating Monad Transformers</a> -- available here: <a>http://okmij.org/ftp/papers/LogicT.pdf</a> @package logict @version 0.6 -- | A backtracking, logic programming monad. -- -- Adapted from the paper /Backtracking, Interleaving, and Terminating -- Monad Transformers/, by Oleg Kiselyov, Chung-chieh Shan, Daniel P. -- Friedman, Amr Sabry -- (<a>http://www.cs.rutgers.edu/~ccshan/logicprog/LogicT-icfp2005.pdf</a>) module Control.Monad.Logic.Class -- | Minimal implementation: msplit class MonadPlus m => MonadLogic m where interleave m1 m2 = msplit m1 >>= maybe m2 (\ (a, m1') -> return a `mplus` interleave m2 m1') m >>- f = do { Just (a, m') <- msplit m; interleave (f a) (m' >>- f) } ifte t th el = msplit t >>= maybe el (\ (a, m) -> th a `mplus` (m >>= th)) once m = do { Just (a, _) <- msplit m; return a } msplit :: MonadLogic m => m a -> m (Maybe (a, m a)) interleave :: MonadLogic m => m a -> m a -> m a (>>-) :: MonadLogic m => m a -> (a -> m b) -> m b ifte :: MonadLogic m => m a -> (a -> m b) -> m b -> m b once :: MonadLogic m => m a -> m a -- | The inverse of msplit. Satisfies the following law: -- -- <pre> -- msplit m >>= reflect == m -- </pre> reflect :: MonadLogic m => Maybe (a, m a) -> m a -- | Inverts a logic computation. If <tt>m</tt> succeeds with at least one -- value, <tt>lnot m</tt> fails. If <tt>m</tt> fails, then <tt>lnot -- m</tt> succeeds the value <tt>()</tt>. lnot :: MonadLogic m => m a -> m () instance (MonadLogic m, Monoid w) => MonadLogic (WriterT w m) instance (MonadLogic m, Monoid w) => MonadLogic (WriterT w m) instance MonadLogic m => MonadLogic (StateT s m) instance MonadLogic m => MonadLogic (StateT s m) instance MonadLogic m => MonadLogic (ReaderT e m) instance MonadLogic [] -- | A backtracking, logic programming monad. -- -- Adapted from the paper /Backtracking, Interleaving, and Terminating -- Monad Transformers/, by Oleg Kiselyov, Chung-chieh Shan, Daniel P. -- Friedman, Amr Sabry -- (<a>http://www.cs.rutgers.edu/~ccshan/logicprog/LogicT-icfp2005.pdf</a>). module Control.Monad.Logic -- | The basic Logic monad, for performing backtracking computations -- returning values of type <tt>a</tt> type Logic = LogicT Identity -- | A smart constructor for Logic computations. logic :: (forall r. (a -> r -> r) -> r -> r) -> Logic a -- | Runs a Logic computation with the specified initial success and -- failure continuations. runLogic :: Logic a -> (a -> r -> r) -> r -> r -- | Extracts the first result from a Logic computation. observe :: Logic a -> a -- | Extracts up to a given number of results from a Logic computation. observeMany :: Int -> Logic a -> [a] -- | Extracts all results from a Logic computation. observeAll :: Logic a -> [a] -- | A monad transformer for performing backtracking computations layered -- over another monad <tt>m</tt> newtype LogicT m a LogicT :: (forall r. (a -> m r -> m r) -> m r -> m r) -> LogicT m a unLogicT :: LogicT m a -> forall r. (a -> m r -> m r) -> m r -> m r -- | Runs a LogicT computation with the specified initial success and -- failure continuations. runLogicT :: LogicT m a -> (a -> m r -> m r) -> m r -> m r -- | Extracts the first result from a LogicT computation, failing -- otherwise. observeT :: Monad m => LogicT m a -> m a -- | Extracts up to a given number of results from a LogicT computation. observeManyT :: Monad m => Int -> LogicT m a -> m [a] -- | Extracts all results from a LogicT computation. observeAllT :: Monad m => LogicT m a -> m [a] instance MonadError e m => MonadError e (LogicT m) instance MonadState s m => MonadState s (LogicT m) instance MonadReader r m => MonadReader r (LogicT m) instance Traversable (LogicT Identity) instance (Monad m, Foldable m) => Foldable (LogicT m) instance Monad m => MonadLogic (LogicT m) instance MonadIO m => MonadIO (LogicT m) instance MonadTrans LogicT instance MonadPlus (LogicT m) instance Monad (LogicT m) instance Alternative (LogicT f) instance Applicative (LogicT f) instance Functor (LogicT f)