Safe Haskell | None |
---|
Trees of predicates.
Exports names which conflict with Prelude names, so you probably want to import this module qualified.
- type Label = Text
- data Pdct a = Pdct Label (Node a)
- data Node a
- rename :: (Text -> Text) -> Pdct a -> Pdct a
- always :: Pdct a
- never :: Pdct a
- operand :: Text -> (a -> Bool) -> Pdct a
- and :: [Pdct a] -> Pdct a
- or :: [Pdct a] -> Pdct a
- not :: Pdct a -> Pdct a
- neverFalse :: Pdct a -> Pdct a
- neverTrue :: Pdct a -> Pdct a
- (&&&) :: Pdct a -> Pdct a -> Pdct a
- (|||) :: Pdct a -> Pdct a -> Pdct a
- boxPdct :: (b -> a) -> Pdct a -> Pdct b
- boxNode :: (b -> a) -> Node a -> Node b
- type Level = Int
- type IndentAmt = Int
- type ShowDiscards = Bool
- showPdct :: IndentAmt -> Level -> Pdct a -> [Chunk]
- eval :: Pdct a -> a -> Maybe Bool
- evaluate :: IndentAmt -> ShowDiscards -> a -> Level -> Pdct a -> (Maybe Bool, [Chunk])
The Pdct tree
And [Pdct a] | None of the Pdct in list may be Just False. An empty list or list with only Nothing is Just True. |
Or [Pdct a] | At least one of the Pdct in the list must be Just True. An empty list or list with only Nothing is Just False. |
Not (Pdct a) | Just True is Just False and vice versa; Nothing remains Nothing. |
NeverFalse (Pdct a) | Just True if the child is Just True; Nothing otherwise. |
NeverTrue (Pdct a) | Just False if the child is Just False; Nothing otherwise. |
Operand (a -> Maybe Bool) | An operand may return Just True or Just False to indicate success or failure. It may also return Nothing to indicate a discard. |
rename :: (Text -> Text) -> Pdct a -> Pdct aSource
Renames the top level of the Pdct. The function you pass will be applied to the old name.
Creating operands
operand :: Text -> (a -> Bool) -> Pdct aSource
Creates a new operand. The Pdct is Just True or Just False, never Nothing.
Creating Pdct from other Pdct
neverFalse :: Pdct a -> Pdct aSource
Turns an existing Pdct to one that never says False. If the underlying predicate returns Just True, the new Pdct also returns Just True. Otherwise, the Pdct returns Nothing.
neverTrue :: Pdct a -> Pdct aSource
Turns an existing Pdct to one that never says True. If the underlying predicate returns Just False, the new Pdct also returns Just False. Otherwise, the Pdct returns Nothing.
boxPdct :: (b -> a) -> Pdct a -> Pdct bSource
Given a function that un-boxes values of type b, changes a Pdct from type a to type b.
boxNode :: (b -> a) -> Node a -> Node bSource
Given a function that un-boxes values of type b, changes a Node from type a to type b.
Showing and evaluating Pdct
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 ShowDiscards = BoolSource
:: IndentAmt | Indent each level by this many spaces. |
-> ShowDiscards | If True, show discarded test results; otherwise, hide them. |
-> a | The subject to evaluate |
-> Level | How many levels deep in the tree we are. Typically you will start at level 0. This determines the level of indentation. |
-> Pdct a | |
-> (Maybe Bool, [Chunk]) |
Verbosely evaluates a Pdct.