-- 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.22.0.2 -- | Trees of predicates. -- -- Exports names which conflict with Prelude names, so you probably want -- to import this module qualified. module Data.Prednote.Predbox type Label = Text -- | Determines whether a result is shown by default. type Hide = Bool -- | A predicate. Each Predbox contains a tree of Node. data Predbox a Predbox :: Label -> (Bool -> Hide) -> Node a -> Predbox a -- | Label used when showing the results pLabel :: Predbox a -> Label -- | As results are computed, this function is applied to the result. If -- this function returns False, then this Predbox will not be shown by -- default in the results. pHide :: Predbox a -> (Bool -> Hide) pNode :: Predbox a -> Node a data Node a -- | Conjunction. If any Predbox in the list is False, the result is False. -- If the list is empty, the result is True. And :: [Predbox a] -> Node a -- | Disjunction. If at least one Predbox in the list is True, the result -- it True. If the list is empty, the result is False. Or :: [Predbox a] -> Node a -- | Negation Not :: (Predbox a) -> Node a -- | Most basic building block. Predicate :: (a -> Bool) -> Node a -- | Creates and labels predicates. predicate :: Label -> (a -> Bool) -> Predbox a -- | Creates And Predbox using a generic name and :: [Predbox a] -> Predbox a -- | Creates Or Predbox using a generic name or :: [Predbox a] -> Predbox a -- | Creates Not Predbox using a generic name not :: Predbox a -> Predbox a -- | Forms a Predbox using and; assigns a generic label. (&&&) :: Predbox a -> Predbox a -> Predbox a -- | Forms a Predbox using or; assigns a generic label. (|||) :: Predbox a -> Predbox a -> Predbox a -- | Always True always :: Predbox a -- | Always False never :: Predbox a -- | Changes a Predbox so it is always hidden by default. hide :: Predbox a -> Predbox a -- | Changes a Predbox so it is always shown by default. show :: Predbox a -> Predbox a -- | Changes a Predbox so that it is hidden if its result is True. hideTrue :: Predbox a -> Predbox a -- | Changes a Predbox so that it is hidden if its result is False. hideFalse :: Predbox a -> Predbox a -- | Renames the top level of the Predbox. The function you pass will be -- applied to the old name. rename :: (Text -> Text) -> Predbox a -> Predbox a -- | The result from evaluating a Predbox. data Result Result :: Label -> Bool -> Hide -> RNode -> Result -- | The label from the original Predbox rLabel :: Result -> Label -- | The boolean result from evaluating the node. If the node is an -- predicate, this is the result of applying the predicate 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 Predbox affects any parent -- Predbox. rHide :: Result -> Hide rNode :: Result -> RNode data RNode RAnd :: [Result] -> RNode ROr :: [Result] -> RNode RNot :: Result -> RNode RPredicate :: Bool -> RNode -- | Applies a Predbox to a particular value, known as the subject. evaluate :: Predbox a -> a -> Result evaluateNode :: Node a -> 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 Predbox tree without evaluating it. showPredbox :: IndentAmt -> Level -> Predbox a -> [Chunk] filter :: Predbox a -> [a] -> [a] -- | Filters a list. Also returns chunks describing the process. verboseFilter :: (a -> Text) -> IndentAmt -> ShowAll -> Predbox a -> [a] -> ([Chunk], [a]) -- | Build a Predbox that compares items. compareBy :: Text -> Text -> (a -> Ordering) -> Ordering -> Predbox a -- | Builds a Predbox for items that might fail to return a comparison. compareByMaybe :: Text -> Text -> (a -> Maybe Ordering) -> Ordering -> Predbox a greaterBy :: Text -> Text -> (a -> Ordering) -> Predbox a lessBy :: Text -> Text -> (a -> Ordering) -> Predbox a equalBy :: Text -> Text -> (a -> Ordering) -> Predbox a greaterEqBy :: Text -> Text -> (a -> Ordering) -> Predbox a lessEqBy :: Text -> Text -> (a -> Ordering) -> Predbox a notEqBy :: Text -> Text -> (a -> Ordering) -> Predbox a -- | Overloaded version of compareBy. compare :: (Show a, Ord a) => Text -> a -> Ordering -> Predbox a greater :: (Show a, Ord a) => Text -> a -> Predbox a less :: (Show a, Ord a) => Text -> a -> Predbox a equal :: (Show a, Ord a) => Text -> a -> Predbox a greaterEq :: (Show a, Ord a) => Text -> a -> Predbox a lessEq :: (Show a, Ord a) => Text -> a -> Predbox a notEq :: (Show a, Ord a) => Text -> a -> Predbox a -- | Parses a string to find the correct comparer; returns the correct -- function to build a Predbox. parseComparer :: Text -> (Ordering -> Predbox a) -> Maybe (Predbox a) instance Eq RNode instance Show RNode instance Eq Result instance Show Result instance Show (Predbox a) instance Contravariant Node instance Contravariant Predbox -- | 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 Predbox on a -- single subject. data Verbosity -- | Do not show any results from the Predbox 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 TestVisibility -- | Do not show any results from this test HideTest :: TestVisibility -- | 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 -> TestVisibility -- | Determines which TestVisibility to use for a particular test. data TestVerbosity TestVerbosity :: TestVisibility -> TestVisibility -> TestVerbosity -- | Use this TestVisibility when the test passes onPass :: TestVerbosity -> TestVisibility -- | Use this TestVisibility when the test fails onFail :: TestVerbosity -> TestVisibility 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 :: Predbox a -> Name -> Test a -- | The test passes if at least a given number of subjects are True. nSubjectsMustBeTrue :: Predbox 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. showTestResult :: IndentAmt -> (a -> Text) -> Maybe TestVerbosity -> TestResult a -> [Chunk] instance Eq Verbosity instance Show Verbosity instance Eq TestVisibility instance Show TestVisibility instance Eq TestVerbosity instance Show TestVerbosity instance Functor TestResult instance Contravariant Test -- | 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 :: (Predbox a) -> RPNToken a TokOperator :: Operator -> RPNToken a data Operator OpAnd :: Operator OpOr :: Operator OpNot :: Operator pushOperand :: Predbox a -> [Predbox a] -> [Predbox a] pushOperator :: Operator -> [Predbox a] -> Either Error [Predbox a] pushToken :: [Predbox a] -> RPNToken a -> Either Error [Predbox a] -- | Parses an RPN expression and returns the resulting Predbox. 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) -> Either Error (Predbox a) instance Show Operator instance Contravariant RPNToken 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] instance Contravariant InfixToken -- | Handles parsing of both infix and RPN Predbox 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 Predbox. operand :: Predbox 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] -> Either Error (Predbox a) instance Eq ExprDesc instance Show ExprDesc instance Contravariant Token module Data.Prednote