-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Build and evaluate trees of predicates
--
-- Build and evaluate trees of predicates. For example, you might build a
-- predicate of the type Int -> Bool. You do this by assembling
-- several predicates into a tree. You can then verbosely evaluate this
-- tree, showing why a particular result is reached.
--
-- prednote also provides modules to test several subjects against a
-- given predicate, and to parse infix or RPN expressions into a tree of
-- predicates.
@package prednote
@version 0.14.0.0
-- | Trees of predicates.
--
-- Exports names which conflict with Prelude names, so you probably want
-- to import this module qualified.
module Data.Prednote.Pdct
type Label = Text
-- | Determines whether a result is shown by default.
type Hide = Bool
-- | A predicate. Each Pdct contains a tree of Node.
data Pdct a
Pdct :: Label -> (Bool -> Hide) -> Node a -> Pdct a
-- | Label used when showing the results
pLabel :: Pdct a -> Label
-- | As results are computed, this function is applied to the result. If
-- this function returns False, then this Pdct will not be shown by
-- default in the results.
pHide :: Pdct a -> (Bool -> Hide)
pNode :: Pdct a -> Node a
data Node a
-- | Conjunction. If any Pdct in the list is False, the result is False. If
-- the list is empty, the result is True.
And :: [Pdct a] -> Node a
-- | Disjunction. If at least one Pdct in the list is True, the result it
-- True. If the list is empty, the result is False.
Or :: [Pdct a] -> Node a
-- | Negation
Not :: (Pdct a) -> Node a
-- | Most basic building block.
Operand :: (a -> Bool) -> Node a
-- | Creates and labels operands.
operand :: Label -> (a -> Bool) -> Pdct a
-- | Creates And Pdct using a generic name
and :: [Pdct a] -> Pdct a
-- | Creates Or Pdct using a generic name
or :: [Pdct a] -> Pdct a
-- | Creates Not Pdct using a generic name
not :: Pdct a -> Pdct a
-- | Forms a Pdct using and; assigns a generic label.
(&&&) :: Pdct a -> Pdct a -> Pdct a
-- | Forms a Pdct using or; assigns a generic label.
(|||) :: Pdct a -> Pdct a -> Pdct a
-- | Always True
always :: Pdct a
-- | Always False
never :: Pdct a
-- | Given a function that un-boxes values of type b, changes a Pdct from
-- type a to type b.
boxPdct :: (b -> a) -> Pdct a -> Pdct b
-- | Given a function that un-boxes values of type b, changes a Node from
-- type a to type b.
boxNode :: (b -> a) -> Node a -> Node b
-- | Changes a Pdct so it is always hidden by default.
hide :: Pdct a -> Pdct a
-- | Changes a Pdct so it is always shown by default.
show :: Pdct a -> Pdct a
-- | Changes a Pdct so that it is hidden if its result is True.
hideTrue :: Pdct a -> Pdct a
-- | Changes a Pdct so that it is hidden if its result is False.
hideFalse :: Pdct a -> Pdct a
-- | Renames the top level of the Pdct. The function you pass will be
-- applied to the old name.
rename :: (Text -> Text) -> Pdct a -> Pdct a
-- | The result from evaluating a Pdct.
data Result
Result :: Label -> Bool -> Hide -> RNode -> Result
-- | The label from the original Pdct
rLabel :: Result -> Label
-- | The boolean result from evaluating the node. If the node is an
-- operand, this is the result of applying the operand function to the
-- subject. Otherwise, this is the result of application of the
-- appropriate boolean operation to the child nodes.
rBool :: Result -> Bool
-- | Is this result hidden in the result by default? Hiding only affects
-- presentation; it does not affect how this Pdct affects any parent
-- Pdct.
rHide :: Result -> Hide
rNode :: Result -> RNode
data RNode
RAnd :: [Result] -> RNode
ROr :: [Result] -> RNode
RNot :: Result -> RNode
ROperand :: Bool -> RNode
-- | Applies a Pdct to a particular value, known as the subject.
evaluate :: a -> Pdct a -> Result
evaluateNode :: a -> Node a -> RNode
-- | The number of spaces to use for each level of indentation.
type IndentAmt = Int
-- | How many levels of indentation to use. Typically you will start this
-- at zero. It is incremented by one for each level as functions descend
-- through the tree.
type Level = Int
type ShowAll = Bool
-- | Shows a Result in a pretty way with colors and indentation.
showResult :: IndentAmt -> ShowAll -> Level -> Result -> [Chunk]
-- | Shows the top of a Result tree and all the child Results. Adds a short
-- label at the top of the tree.
showTopResult :: Text -> IndentAmt -> Level -> ShowAll -> Result -> [Chunk]
-- | Shows a Pdct tree without evaluating it.
showPdct :: IndentAmt -> Level -> Pdct a -> [Chunk]
filter :: Pdct a -> [a] -> [a]
-- | Filters a list. Also returns chunks describing the process.
verboseFilter :: (a -> Text) -> IndentAmt -> ShowAll -> Pdct a -> [a] -> ([Chunk], [a])
-- | Build a Pdct that compares items.
compareBy :: Text -> Text -> (a -> Ordering) -> Ordering -> Pdct a
-- | Builds a Pdct for items that might fail to return a comparison.
compareByMaybe :: Text -> Text -> (a -> Maybe Ordering) -> Ordering -> Pdct a
greaterBy :: Text -> Text -> (a -> Ordering) -> Pdct a
lessBy :: Text -> Text -> (a -> Ordering) -> Pdct a
equalBy :: Text -> Text -> (a -> Ordering) -> Pdct a
greaterEqBy :: Text -> Text -> (a -> Ordering) -> Pdct a
lessEqBy :: Text -> Text -> (a -> Ordering) -> Pdct a
notEqBy :: Text -> Text -> (a -> Ordering) -> Pdct a
-- | Overloaded version of compareBy.
compare :: (Show a, Ord a) => Text -> a -> Ordering -> Pdct a
greater :: (Show a, Ord a) => Text -> a -> Pdct a
less :: (Show a, Ord a) => Text -> a -> Pdct a
equal :: (Show a, Ord a) => Text -> a -> Pdct a
greaterEq :: (Show a, Ord a) => Text -> a -> Pdct a
lessEq :: (Show a, Ord a) => Text -> a -> Pdct a
notEq :: (Show a, Ord a) => Text -> a -> Pdct a
-- | Parses a string to find the correct comparer; returns the correct
-- function to build a Pdct.
parseComparer :: Text -> (Ordering -> Pdct a) -> Maybe (Pdct a)
instance Eq RNode
instance Show RNode
instance Eq Result
instance Show Result
instance Show (Pdct a)
-- | Postfix, or RPN, expression parsing.
--
-- This module parses RPN expressions where the operands are predicates
-- and the operators are one of and, or, or
-- not, where and and or are binary and
-- not is unary.
module Data.Prednote.Expressions.RPN
type Error = Text
data RPNToken a
TokOperand :: (Pdct a) -> RPNToken a
TokOperator :: Operator -> RPNToken a
data Operator
OpAnd :: Operator
OpOr :: Operator
OpNot :: Operator
pushOperand :: Pdct a -> [Pdct a] -> [Pdct a]
pushOperator :: Operator -> [Pdct a] -> Exceptional Error [Pdct a]
pushToken :: [Pdct a] -> RPNToken a -> Exceptional Error [Pdct a]
-- | Parses an RPN expression and returns the resulting Pdct. Fails if
-- there are no operands left on the stack or if there are multiple
-- operands left on the stack; the stack must contain exactly one operand
-- in order to succeed.
parseRPN :: Foldable f => f (RPNToken a) -> Exceptional Error (Pdct a)
instance Show Operator
module Data.Prednote.Expressions.Infix
data InfixToken a
TokRPN :: (RPNToken a) -> InfixToken a
TokParen :: Paren -> InfixToken a
data Paren
Open :: Paren
Close :: Paren
-- | Creates an RPN expression from an infix one. Fails only if there are
-- mismatched parentheses. It is possible to create a nonsensical RPN
-- expression; the RPN parser must catch this.
createRPN :: Foldable f => f (InfixToken a) -> Maybe [RPNToken a]
-- | Handles parsing of both infix and RPN Pdct expressions.
module Data.Prednote.Expressions
-- | Is this an infix or RPN expression?
data ExprDesc
Infix :: ExprDesc
RPN :: ExprDesc
type Error = Text
-- | A single type for both RPN tokens and infix tokens.
data Token a
-- | Creates Operands from Pdct.
operand :: Pdct a -> Token a
-- | The And operator
opAnd :: Token a
-- | The Or operator
opOr :: Token a
-- | The Not operator
opNot :: Token a
-- | Open parentheses
openParen :: Token a
-- | Close parentheses
closeParen :: Token a
-- | Parses expressions. Fails if the expression is nonsensical in some way
-- (for example, unbalanced parentheses, parentheses in an RPN
-- expression, or multiple stack values remaining.) Works by first
-- changing infix expressions to RPN ones.
parseExpression :: ExprDesc -> [Token a] -> Exceptional Error (Pdct a)
instance Eq ExprDesc
instance Show ExprDesc
-- | Helps you build tests that run against a series of items.
module Data.Prednote.Test
-- | The name of a test or of a group.
type Name = Text
-- | How verbose to be when showing the results of running a Pdct on a
-- single subject.
data Verbosity
-- | Do not show any results from the Pdct
HideAll :: Verbosity
-- | Show results according to the default settings provided in the Result
-- itself
ShowDefaults :: Verbosity
-- | Show all Result
ShowAll :: Verbosity
-- | Use this verbosity for subjects that are True
type TrueVerbosity = Verbosity
-- | Use this verbosity for subjects that are False
type FalseVerbosity = Verbosity
-- | Determines whether to show any of the results from a single test.
data ShowTest
-- | Do not show any results from this test
HideTest :: ShowTest
-- | Show the first line, which indicates whether the test passed or failed
-- and gives the label for the test. Whether to show individual subjects
-- is determined by the TrueVerbosity and FalseVerbosity.
ShowFirstLine :: TrueVerbosity -> FalseVerbosity -> ShowTest
-- | Determines which ShowTest to use for a particular test.
data TestVerbosity
TestVerbosity :: ShowTest -> ShowTest -> TestVerbosity
-- | Use this ShowTest when the test passes
onPass :: TestVerbosity -> ShowTest
-- | Use this ShowTest when the test fails
onFail :: TestVerbosity -> ShowTest
type Pass = Bool
-- | A single test.
data Test a
Test :: Name -> ([Result] -> Pass) -> (a -> Result) -> TestVerbosity -> Test a
testName :: Test a -> Name
-- | Applied to the results of all applications of testFunc; determines
-- whether the test passes or fails.
testPass :: Test a -> [Result] -> Pass
-- | This function is applied to each subject.
testFunc :: Test a -> a -> Result
-- | Default verbosity for the test.
testVerbosity :: Test a -> TestVerbosity
data TestResult a
TestResult :: Name -> Pass -> [(a, Result)] -> TestVerbosity -> TestResult a
resultName :: TestResult a -> Name
resultPass :: TestResult a -> Pass
resultSubjects :: TestResult a -> [(a, Result)]
resultDefaultVerbosity :: TestResult a -> TestVerbosity
-- | The test passes if each subject returns True.
eachSubjectMustBeTrue :: Pdct a -> Name -> Test a
-- | The test passes if at least a given number of subjects are True.
nSubjectsMustBeTrue :: Pdct a -> Name -> Int -> Test a
-- | Evaluates a test for a given list of subjects.
evalTest :: Test a -> [a] -> TestResult a
-- | Shows a result with indenting.
showResult :: IndentAmt -> (a -> Text) -> Maybe TestVerbosity -> TestResult a -> [Chunk]
instance Eq Verbosity
instance Show Verbosity
instance Eq ShowTest
instance Show ShowTest
instance Eq TestVerbosity
instance Show TestVerbosity