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
- type Hide = Bool
- data Pdct a = Pdct {}
- data Node a
- operand :: Label -> (a -> Bool) -> Pdct a
- and :: [Pdct a] -> Pdct a
- or :: [Pdct a] -> Pdct a
- not :: Pdct a -> Pdct a
- (&&&) :: Pdct a -> Pdct a -> Pdct a
- (|||) :: Pdct a -> Pdct a -> Pdct a
- always :: Pdct a
- never :: Pdct a
- boxPdct :: (b -> a) -> Pdct a -> Pdct b
- boxNode :: (b -> a) -> Node a -> Node b
- hide :: Pdct a -> Pdct a
- show :: Pdct a -> Pdct a
- hideTrue :: Pdct a -> Pdct a
- hideFalse :: Pdct a -> Pdct a
- rename :: (Text -> Text) -> Pdct a -> Pdct a
- data Result = Result {}
- data RNode
- evaluate :: a -> Pdct a -> Result
- evaluateNode :: a -> Node a -> RNode
- type IndentAmt = Int
- type Level = Int
- type ShowAll = Bool
- showResult :: IndentAmt -> ShowAll -> Level -> Result -> [Chunk]
- showTopResult :: Text -> IndentAmt -> Level -> ShowAll -> Result -> [Chunk]
- showPdct :: IndentAmt -> Level -> Pdct a -> [Chunk]
- filter :: Pdct a -> [a] -> [a]
- verboseFilter :: (a -> Text) -> IndentAmt -> ShowAll -> Pdct a -> [a] -> ([Chunk], [a])
- compareBy :: Text -> Text -> (a -> Ordering) -> Ordering -> Pdct a
- 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
- 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
- parseComparer :: Text -> (Ordering -> Pdct a) -> Maybe (Pdct a)
The Pdct tree
A predicate. Each Pdct contains a tree of Node.
And [Pdct a] | Conjunction. If any Pdct in the list is False, the result is False. If the list is empty, the result is True. |
Or [Pdct 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. |
Not (Pdct a) | Negation |
Operand (a -> Bool) | Most basic building block. |
Creating Pdct.
All functions create Pdct that are shown by default.
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.
Controlling whether Pdct are shown in the results
Renaming Pdct
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.
Result
The result from evaluating a Pdct.
Result | |
|
Showing and evaluating Pdct
evaluateNode :: a -> Node a -> RNodeSource
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.
:: IndentAmt | Indent each level by this many spaces |
-> ShowAll | If True, shows all Pdct, even ones where |
-> Level | How deep in the tree we are; this increments by one for each level of descent. |
-> Result | The result to show |
-> [Chunk] |
Shows a Result in a pretty way with colors and indentation.
:: Text | Label to add to the top of the tree. |
-> IndentAmt | Indent each level by this many spaces |
-> Level | Indent the top by this many levels |
-> ShowAll | If True, shows all Pdct, even ones where |
-> Result | The result to show |
-> [Chunk] |
Shows the top of a Result tree and all the child Results. Adds a short label at the top of the tree.
:: (a -> Text) | How to describe each subject |
-> IndentAmt | Indent each level by this many spaces |
-> ShowAll | If True, shows all Pdct, even ones where |
-> Pdct a | Used to perform the filtering |
-> [a] | |
-> ([Chunk], [a]) |
Filters a list. Also returns chunks describing the process.
Helpers for building common Pdct
Non-overloaded
:: Text | How to show the item being compared; used to describe the Pdct |
-> Text | Description of the type of thing that is being matched |
-> (a -> Ordering) | How to compare an item against the right hand side. Return LT if the item is less than the right hand side; GT if greater; EQ if equal to the right hand side. |
-> Ordering | When subjects are compared, this ordering must be the result in order for the Pdct to be True; otherwise it is False. The subject will be on the left hand side. |
-> Pdct a |
Build a Pdct that compares items.
:: Text | How to show the item being compared |
-> Text | Description of type of thing being matched |
-> (a -> Maybe Ordering) | How to compare against right hand side. If Nothing, a Pdct that always returns False is returned. |
-> Ordering | Ordering that must result for the Pdct to be True |
-> Pdct a |
Builds a Pdct for items that might fail to return a comparison.
Overloaded
:: (Show a, Ord a) | |
=> Text | Description of the type of thing being matched |
-> a | The right hand side of the comparison. |
-> Ordering | When subjects are compared, this ordering must be the result in order for the Pdct to be True; otherwise it is False. The subject will be on the left hand side. |
-> Pdct a |
Overloaded version of compareBy
.
:: Text | The string with the comparer to be parsed |
-> (Ordering -> Pdct a) | A function that, when given an ordering, returns a Pdct |
-> Maybe (Pdct a) | If an invalid comparer string is given, Nothing; otherwise, the Pdct. |
Parses a string to find the correct comparer; returns the correct function to build a Pdct.