logict-0.7.0.2: A backtracking logic-programming monad.

Copyright | (c) Dan Doel
License | BSD3
Maintainer | dan.doel@gmail.com
Stability | experimental
Portability | non-portable (multi-parameter type classes)
Safe Haskell | Safe
Language | Haskell98

Control.Monad.Logic

Contents

- The Logic monad
- The LogicT monad transformer

Description

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 (http://okmij.org/ftp/papers/LogicT.pdf).

Synopsis

- module Control.Monad.Logic.Class
- type Logic = LogicT Identity
- logic :: (forall r. (a -> r -> r) -> r -> r) -> Logic a
- runLogic :: Logic a -> (a -> r -> r) -> r -> r
- observe :: Logic a -> a
- observeMany :: Int -> Logic a -> [a]
- observeAll :: Logic a -> [a]
- newtype LogicT m a = LogicT {
  - unLogicT :: forall r. (a -> m r -> m r) -> m r -> m r
  }
- runLogicT :: LogicT m a -> (a -> m r -> m r) -> m r -> m r
- observeT :: MonadFail m => LogicT m a -> m a
- observeManyT :: Monad m => Int -> LogicT m a -> m [a]
- observeAllT :: Monad m => LogicT m a -> m [a]

# Documentation

module Control.Monad.Logic.Class

# The Logic monad

type Logic = LogicT Identity Source #

The basic Logic monad, for performing backtracking computations returning values of type `a`.

logic :: (forall r. (a -> r -> r) -> r -> r) -> Logic a Source #

A smart constructor for Logic computations.

runLogic :: Logic a -> (a -> r -> r) -> r -> r Source #

Runs a Logic computation with the specified initial success and failure continuations.

observe :: Logic a -> a Source #

Extracts the first result from a Logic computation.

observeMany :: Int -> Logic a -> [a] Source #

Extracts up to a given number of results from a Logic computation.

observeAll :: Logic a -> [a] Source #

Extracts all results from a Logic computation.

# The LogicT monad transformer

newtype LogicT m a Source #

A monad transformer for performing backtracking computations layered over another monad `m`.

Constructors

LogicT |

Fields

- unLogicT :: forall r. (a -> m r -> m r) -> m r -> m r

#### Instances

Instances details

MonadTrans LogicT Source # |
Instance details Defined in Control.Monad.Logic Methods lift :: Monad m => m a -> LogicT m a
MonadReader r m => MonadReader r (LogicT m) Source # |
Instance details Defined in Control.Monad.Logic Methods ask :: LogicT m r local :: (r -> r) -> LogicT m a -> LogicT m a reader :: (r -> a) -> LogicT m a
MonadState s m => MonadState s (LogicT m) Source # |
Instance details Defined in Control.Monad.Logic Methods get :: LogicT m s put :: s -> LogicT m () state :: (s -> (a, s)) -> LogicT m a
MonadError e m => MonadError e (LogicT m) Source # |
Instance details Defined in Control.Monad.Logic Methods throwError :: e -> LogicT m a catchError :: LogicT m a -> (e -> LogicT m a) -> LogicT m a
Monad (LogicT m) Source # |
Instance details Defined in Control.Monad.Logic Methods (>>=) :: LogicT m a -> (a -> LogicT m b) -> LogicT m b (>>) :: LogicT m a -> LogicT m b -> LogicT m b return :: a -> LogicT m a
Functor (LogicT f) Source # |
Instance details Defined in Control.Monad.Logic Methods fmap :: (a -> b) -> LogicT f a -> LogicT f b (<$) :: a -> LogicT f b -> LogicT f a
MonadFail (LogicT m) Source # |
Instance details Defined in Control.Monad.Logic Methods fail :: String -> LogicT m a
Applicative (LogicT f) Source # |
Instance details Defined in Control.Monad.Logic Methods pure :: a -> LogicT f a (<*>) :: LogicT f (a -> b) -> LogicT f a -> LogicT f b liftA2 :: (a -> b -> c) -> LogicT f a -> LogicT f b -> LogicT f c (*>) :: LogicT f a -> LogicT f b -> LogicT f b (<*) :: LogicT f a -> LogicT f b -> LogicT f a
(Monad m, Foldable m) => Foldable (LogicT m) Source # |

Instance details

Defined in Control.Monad.Logic

Methods

fold :: Monoid m0 => LogicT m m0 -> m0

foldMap :: Monoid m0 => (a -> m0) -> LogicT m a -> m0

foldMap' :: Monoid m0 => (a -> m0) -> LogicT m a -> m0

foldr :: (a -> b -> b) -> b -> LogicT m a -> b

foldr' :: (a -> b -> b) -> b -> LogicT m a -> b

foldl :: (b -> a -> b) -> b -> LogicT m a -> b

foldl' :: (b -> a -> b) -> b -> LogicT m a -> b

foldr1 :: (a -> a -> a) -> LogicT m a -> a

foldl1 :: (a -> a -> a) -> LogicT m a -> a

toList :: LogicT m a -> [a]

null :: LogicT m a -> Bool

length :: LogicT m a -> Int

elem :: Eq a => a -> LogicT m a -> Bool

maximum :: Ord a => LogicT m a -> a

minimum :: Ord a => LogicT m a -> a

sum :: Num a => LogicT m a -> a

product :: Num a => LogicT m a -> a

Foldable (LogicT Identity) Source # |

Instance details

Defined in Control.Monad.Logic

Methods

fold :: Monoid m => LogicT Identity m -> m

foldMap :: Monoid m => (a -> m) -> LogicT Identity a -> m

foldMap' :: Monoid m => (a -> m) -> LogicT Identity a -> m

foldr :: (a -> b -> b) -> b -> LogicT Identity a -> b

foldr' :: (a -> b -> b) -> b -> LogicT Identity a -> b

foldl :: (b -> a -> b) -> b -> LogicT Identity a -> b

foldl' :: (b -> a -> b) -> b -> LogicT Identity a -> b

foldr1 :: (a -> a -> a) -> LogicT Identity a -> a

foldl1 :: (a -> a -> a) -> LogicT Identity a -> a

toList :: LogicT Identity a -> [a]

null :: LogicT Identity a -> Bool

length :: LogicT Identity a -> Int

elem :: Eq a => a -> LogicT Identity a -> Bool

maximum :: Ord a => LogicT Identity a -> a

minimum :: Ord a => LogicT Identity a -> a

sum :: Num a => LogicT Identity a -> a

product :: Num a => LogicT Identity a -> a

Traversable (LogicT Identity) Source # |
Instance details Defined in Control.Monad.Logic Methods traverse :: Applicative f => (a -> f b) -> LogicT Identity a -> f (LogicT Identity b) sequenceA :: Applicative f => LogicT Identity (f a) -> f (LogicT Identity a) mapM :: Monad m => (a -> m b) -> LogicT Identity a -> m (LogicT Identity b) sequence :: Monad m => LogicT Identity (m a) -> m (LogicT Identity a)
MonadIO m => MonadIO (LogicT m) Source # |
Instance details Defined in Control.Monad.Logic Methods liftIO :: IO a -> LogicT m a
MonadPlus (LogicT m) Source # |
Instance details Defined in Control.Monad.Logic Methods mzero :: LogicT m a mplus :: LogicT m a -> LogicT m a -> LogicT m a
Alternative (LogicT f) Source # |
Instance details Defined in Control.Monad.Logic Methods empty :: LogicT f a (<|>) :: LogicT f a -> LogicT f a -> LogicT f a some :: LogicT f a -> LogicT f [a] many :: LogicT f a -> LogicT f [a]
Monad m => MonadLogic (LogicT m) Source # |

Instance details

Defined in Control.Monad.Logic

Methods

msplit :: LogicT m a -> LogicT m (Maybe (a, LogicT m a)) Source #

interleave :: LogicT m a -> LogicT m a -> LogicT m a Source #

(>>-) :: LogicT m a -> (a -> LogicT m b) -> LogicT m b Source #

ifte :: LogicT m a -> (a -> LogicT m b) -> LogicT m b -> LogicT m b Source #

once :: LogicT m a -> LogicT m a Source #

lnot :: LogicT m a -> LogicT m () Source #

runLogicT :: LogicT m a -> (a -> m r -> m r) -> m r -> m r Source #

Runs a LogicT computation with the specified initial success and failure continuations.

observeT :: MonadFail m => LogicT m a -> m a Source #

Extracts the first result from a LogicT computation, failing otherwise.

observeManyT :: Monad m => Int -> LogicT m a -> m [a] Source #

Extracts up to a given number of results from a LogicT computation.

observeAllT :: Monad m => LogicT m a -> m [a] Source #

Extracts all results from a LogicT computation.