packages feed

logict 0.4.2 → 0.5.0

raw patch · 3 files changed

+33/−56 lines, 3 filesdep ~basedep ~mtlPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, mtl

API changes (from Hackage documentation)

- Control.Monad.Logic: Logic :: LogicT Identity a -> Logic a
- Control.Monad.Logic: instance Alternative Logic
- Control.Monad.Logic: instance Applicative Logic
- Control.Monad.Logic: instance Applicative f => Alternative (LogicT f)
- Control.Monad.Logic: instance Applicative f => Applicative (LogicT f)
- Control.Monad.Logic: instance Foldable Logic
- Control.Monad.Logic: instance Functor Logic
- Control.Monad.Logic: instance Functor f => Functor (LogicT f)
- Control.Monad.Logic: instance Monad Logic
- Control.Monad.Logic: instance Monad m => Monad (LogicT m)
- Control.Monad.Logic: instance Monad m => MonadPlus (LogicT m)
- Control.Monad.Logic: instance MonadLogic Logic
- Control.Monad.Logic: instance MonadPlus Logic
- Control.Monad.Logic: instance Traversable Logic
- Control.Monad.Logic: newtype Logic a
- Control.Monad.Logic: unLogic :: Logic a -> LogicT Identity a
+ Control.Monad.Logic: instance (Monad m, Foldable m) => Foldable (LogicT m)
+ Control.Monad.Logic: instance Alternative (LogicT f)
+ Control.Monad.Logic: instance Applicative (LogicT f)
+ Control.Monad.Logic: instance Functor (LogicT f)
+ Control.Monad.Logic: instance Monad (LogicT m)
+ Control.Monad.Logic: instance MonadPlus (LogicT m)
+ Control.Monad.Logic: instance Traversable (LogicT Identity)
+ Control.Monad.Logic: logic :: (forall r. (a -> r -> r) -> r -> r) -> Logic a
+ Control.Monad.Logic: type Logic = LogicT Identity
- Control.Monad.Logic: LogicT :: (forall ans. SK (m ans) a -> FK (m ans) -> m ans) -> LogicT m a
+ Control.Monad.Logic: LogicT :: (forall r. (a -> m r -> m r) -> m r -> m r) -> LogicT m a
- Control.Monad.Logic: unLogicT :: LogicT m a -> forall ans. SK (m ans) a -> FK (m ans) -> m ans
+ Control.Monad.Logic: unLogicT :: LogicT m a -> forall r. (a -> m r -> m r) -> m r -> m r

Files

Control/Monad/Logic.hs view
@@ -22,7 +22,8 @@ module Control.Monad.Logic (     module Control.Monad.Logic.Class,     -- * The Logic monad-    Logic(..),+    Logic,+    logic,     runLogic,     observe,     observeMany,@@ -47,19 +48,17 @@ import Control.Monad.State.Class import Control.Monad.Error.Class +import Data.Monoid (Monoid(mappend, mempty)) import qualified Data.Foldable as F import qualified Data.Traversable as T  import Control.Monad.Logic.Class -type SK r a = a -> r -> r-type FK a = a- ------------------------------------------------------------------------- -- | A monad transformer for performing backtracking computations -- layered over another monad 'm' newtype LogicT m a =-    LogicT { unLogicT :: forall ans. SK (m ans) a -> FK (m ans) -> m ans }+    LogicT { unLogicT :: forall r. (a -> m r -> m r) -> m r -> m r }  ------------------------------------------------------------------------- -- | Extracts the first result from a LogicT computation,@@ -92,50 +91,56 @@ ------------------------------------------------------------------------- -- | The basic Logic monad, for performing backtracking computations -- returning values of type 'a'-newtype Logic a = Logic { unLogic :: LogicT Identity a }---        deriving (Functor, Applicative, Alternative, Monad, MonadPlus, MonadLogic)+type Logic = LogicT Identity  -------------------------------------------------------------------------+-- | A smart constructor for Logic computations.+logic :: (forall r. (a -> r -> r) -> r -> r) -> Logic a+logic f = LogicT $ \k -> Identity .+                         f (\a -> runIdentity . k a . Identity) .+                         runIdentity++------------------------------------------------------------------------- -- | Extracts the first result from a Logic computation. observe :: Logic a -> a-observe = runIdentity . observeT . unLogic+observe = runIdentity . observeT   ------------------------------------------------------------------------- -- | Extracts all results from a Logic computation. observeAll :: Logic a -> [a]-observeAll = runIdentity . observeAllT . unLogic+observeAll = runIdentity . observeAllT  ------------------------------------------------------------------------- -- | Extracts up to a given number of results from a Logic computation. observeMany :: Int -> Logic a -> [a]-observeMany i = runIdentity . observeManyT i . unLogic+observeMany i = runIdentity . observeManyT i  ------------------------------------------------------------------------- -- | Runs a Logic computation with the specified initial success and -- failure continuations. runLogic :: Logic a -> (a -> r -> r) -> r -> r-runLogic l s f = runIdentity $ unLogicT (unLogic l) si fi+runLogic l s f = runIdentity $ unLogicT l si fi  where  si = fmap . s  fi = Identity f -instance (Functor f) => Functor (LogicT f) where+instance Functor (LogicT f) where     fmap f lt = LogicT $ \sk fk -> unLogicT lt (sk . f) fk -instance (Applicative f) => Applicative (LogicT f) where+instance Applicative (LogicT f) where     pure a = LogicT $ \sk fk -> sk a fk     f <*> a = LogicT $ \sk fk -> unLogicT f (\g fk' -> unLogicT a (sk . g) fk') fk -instance (Applicative f) => Alternative (LogicT f) where+instance Alternative (LogicT f) where     empty = LogicT $ \_ fk -> fk     f1 <|> f2 = LogicT $ \sk fk -> unLogicT f1 sk (unLogicT f2 sk fk) -instance (Monad m) => Monad (LogicT m) where+instance Monad (LogicT m) where     return a = LogicT $ \sk fk -> sk a fk     m >>= f = LogicT $ \sk fk -> unLogicT m (\a fk' -> unLogicT (f a) sk fk') fk     fail _ = LogicT $ \_ fk -> fk -instance (Monad m) => MonadPlus (LogicT m) where+instance MonadPlus (LogicT m) where     mzero = LogicT $ \_ fk -> fk     m1 `mplus` m2 = LogicT $ \sk fk -> unLogicT m1 sk (unLogicT m2 sk fk) @@ -150,52 +155,25 @@      where      ssk a fk = return $ Just (a, (lift fk >>= reflect)) -instance F.Foldable Logic where-    foldr f z l = runLogic l f z+instance (Monad m, F.Foldable m) => F.Foldable (LogicT m) where+    foldMap f m = F.fold $ unLogicT m (liftM . mappend . f) (return mempty) -instance T.Traversable Logic where+instance T.Traversable (LogicT Identity) where     traverse g l = runLogic l (\a ft -> cons <$> g a <*> ft) (pure mzero)      where cons a l' = return a `mplus` l' --- haddock doesn't like generalized newtype deriving, so I'm writing--- instances by hand-instance Functor Logic where-    fmap f = Logic . fmap f . unLogic--instance Applicative Logic where-    pure = Logic . return-    (Logic f) <*> (Logic a) = (Logic . LogicT) (\sk fk ->-      unLogicT f (\g fk' -> unLogicT a (sk . g) fk') fk)--instance Alternative Logic where-    empty = (Logic . LogicT) (\_ fk -> fk)-    (Logic a1) <|> (Logic a2) = (Logic . LogicT) (\sk fk ->-      unLogicT a1 sk (unLogicT a2 sk fk))--instance Monad Logic where-    return = Logic . return-    m >>= f = Logic $ unLogic m >>= unLogic . f-    fail   = Logic . fail--instance MonadPlus Logic where-    mzero = Logic mzero-    m1 `mplus` m2 = Logic $ unLogic m1 `mplus` unLogic m2--instance MonadLogic Logic where-    msplit m = Logic . liftM (liftM (fmap Logic)) $ msplit (unLogic m)- -- Needs undecidable instances-instance (MonadReader r m) => MonadReader r (LogicT m) where+instance MonadReader r m => MonadReader r (LogicT m) where     ask = lift ask     local f m = LogicT $ \sk fk -> unLogicT m ((local f .) . sk) (local f fk)  -- Needs undecidable instances-instance (MonadState s m) => MonadState s (LogicT m) where+instance MonadState s m => MonadState s (LogicT m) where     get = lift get     put = lift . put  -- Needs undecidable instances-instance (MonadError e m) => MonadError e (LogicT m) where+instance MonadError e m => MonadError e (LogicT m) where   throwError = lift . throwError   catchError m h = LogicT $ \sk fk -> let       handle r = r `catchError` \e -> unLogicT (h e) sk fk
Control/Monad/Logic/Class.hs view
@@ -1,4 +1,3 @@- ------------------------------------------------------------------------- -- | -- Module      : Control.Monad.Logic.Class@@ -121,13 +120,13 @@ -- computation. The results are similar for StateT. However, this is likely not -- an issue as most uses of msplit (all the ones in this library, at least) would -- not allow for that anyway.-instance (MonadLogic m) => MonadLogic (ReaderT e m) where+instance MonadLogic m => MonadLogic (ReaderT e m) where     msplit rm = ReaderT $ \e -> do r <- msplit $ runReaderT rm e                                    case r of                                      Nothing -> return Nothing                                      Just (a, m) -> return (Just (a, lift m)) -instance (MonadLogic m) => MonadLogic (StrictST.StateT s m) where+instance MonadLogic m => MonadLogic (StrictST.StateT s m) where     msplit sm = StrictST.StateT $ \s ->                     do r <- msplit (StrictST.runStateT sm s)                        case r of@@ -147,7 +146,7 @@      once ma = StrictST.StateT $ \s -> once (StrictST.runStateT ma s) -instance (MonadLogic m) => MonadLogic (LazyST.StateT s m) where+instance MonadLogic m => MonadLogic (LazyST.StateT s m) where     msplit sm = LazyST.StateT $ \s ->                     do r <- msplit (LazyST.runStateT sm s)                        case r of
logict.cabal view
@@ -1,5 +1,5 @@ Name:                   logict-Version:                0.4.2+Version:                0.5.0 Description:            A continuation-based, backtracking, logic programming monad.                         An adaptation of the two-continuation implementation found                         in the paper "Backtracking, Interleaving, and Terminating@@ -9,7 +9,8 @@ Category:               Control License:                BSD3 License-File:           LICENSE-Copyright:              Copyright (c) 2007-2010, Dan Doel+Copyright:              Copyright (c) 2007-2010, Dan Doel,+                        Copyright (c) 2011, Edward Kmett Author:                 Dan Doel Maintainer:             dan.doel@gmail.com Homepage:               http://code.haskell.org/~dolio/logict@@ -26,4 +27,3 @@                         Rank2Types,                         FlexibleInstances GHC-Options:            -O2 -Wall-