úÎ.‡+%
+non-portable (multi-parameter type classes)experimentaldan.doel@gmail.comMinimal implementation: msplit
>Attempts to split the computation, giving access to the first
) result. Satisfies the following laws:
/ msplit mzero == return Nothing
5 msplit (return a `mplus` m) == return (Just (a, m))
;Fair disjunction. It is possible for a logical computation
B to have an infinite number of potential results, for instance:
) odds = return 1 `mplus` liftM (2+) odds
FSuch computations can cause problems in some circumstances. Consider:
do x <- odds `mplus` return 2
' if even x then return x else mzero
*Such a computation may never consider the 'return 2', and will
C therefore never terminate. By contrast, interleave ensures fair
3 consideration of both branches of a disjunction
?Fair conjunction. Similarly to the previous function, consider
) the distributivity law for MonadPlus:
1 (mplus a b) >>= k = (a >>= k) `mplus` (b >>= k)
If 'a >>= k': can backtrack arbitrarily many tmes, (b >>= k) may never
H be considered. (>>-) takes similar care to consider both branches of
a disjunctive computation.
-Logical conditional. The equivalent of Prolog's soft-cut. If its
E first argument succeeds at all, then the results will be fed into
? the success branch. Otherwise, the failure branch is taken.
! satisfies the following laws:
) ifte (return a) th el == th a
' ifte mzero th el == el
< ifte (return a `mplus` m) th el == th a `mplus` (m >>= th)
BPruning. Selects one result out of many. Useful for when multiple
H results of a computation will be equivalent, or should be treated as
such.
4The inverse of msplit. Satisfies the following law:
msplit m >>= reflect == m
+non-portable (multi-parameter type classes)experimentaldan.doel@gmail.com@The basic Logic monad, for performing backtracking computations
returning values of type a
=A monad transformer for performing backtracking computations
layered over another monad m
5Extracts the first result from a LogicT computation,
failing otherwise.
0Extracts all results from a LogicT computation.
DExtracts up to a given number of results from a LogicT computation.
ARuns a LogicT computation with the specified initial success and
failure continuations.
4Extracts the first result from a Logic computation.
/Extracts all results from a Logic computation.
CExtracts up to a given number of results from a Logic computation.
@Runs a Logic computation with the specified initial success and
failure continuations.
< !"#$%&'()*+,-./0123456789:;<=>?@A
B
! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ABCDBCEBCFBCGHlogict-0.2.3Control.Monad.Logic.ClassControl.Monad.Logic
MonadLogicmsplit
interleave>>-ifteoncereflectLogicLogicTobserveTobserveAllTobserveManyT runLogicTobserve
observeAllobserveManyrunLogicunLogicunLogicTFKSKbaseGHC.Basefail>>=>>returnMonadFunctor
Control.Monad MonadPlusapliftM5liftM4liftM3liftM2liftMunlesswhenreplicateM_
replicateMfoldM_foldM zipWithM_zipWithMmapAndUnzipMjoinforever<=<>=>msumforM_forMfilterMguardmapM_mapM sequence_sequence=<<mplusmzerofmapmtl-1.1.1.0Control.Monad.Translift
MonadTransliftIOMonadIO