prednote-0.16.0.0: Build and evaluate trees of predicates

Safe HaskellNone

Data.Prednote.Pdct

Contents

Description

Trees of predicates.

Exports names which conflict with Prelude names, so you probably want to import this module qualified.

Synopsis

The Pdct tree

type Hide = BoolSource

Determines whether a result is shown by default.

data Pdct a Source

A predicate. Each Pdct contains a tree of Node.

Constructors

Pdct 

Fields

pLabel :: Label

Label used when showing the results

pHide :: Bool -> Hide

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.

pNode :: Node a
 

Instances

Show (Pdct a) 

data Node a Source

Constructors

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.

operand :: Label -> (a -> Bool) -> Pdct aSource

Creates and labels operands.

and :: [Pdct a] -> Pdct aSource

Creates And Pdct using a generic name

or :: [Pdct a] -> Pdct aSource

Creates Or Pdct using a generic name

not :: Pdct a -> Pdct aSource

Creates Not Pdct using a generic name

(&&&) :: Pdct a -> Pdct a -> Pdct aSource

Forms a Pdct using and; assigns a generic label.

(|||) :: Pdct a -> Pdct a -> Pdct aSource

Forms a Pdct using or; assigns a generic label.

always :: Pdct aSource

Always True

never :: Pdct aSource

Always False

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

hide :: Pdct a -> Pdct aSource

Changes a Pdct so it is always hidden by default.

show :: Pdct a -> Pdct aSource

Changes a Pdct so it is always shown by default.

hideTrue :: Pdct a -> Pdct aSource

Changes a Pdct so that it is hidden if its result is True.

hideFalse :: Pdct a -> Pdct aSource

Changes a Pdct so that it is hidden if its result is False.

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

data Result Source

The result from evaluating a Pdct.

Constructors

Result 

Fields

rLabel :: Label

The label from the original Pdct

rBool :: Bool

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.

rHide :: Hide

Is this result hidden in the result by default? Hiding only affects presentation; it does not affect how this Pdct affects any parent Pdct.

rNode :: RNode
 

Instances

data RNode Source

Constructors

RAnd [Result] 
ROr [Result] 
RNot Result 
ROperand Bool 

Instances

Showing and evaluating Pdct

evaluate :: a -> Pdct a -> ResultSource

Applies a Pdct to a particular value, known as the subject.

type IndentAmt = IntSource

The number of spaces to use for each level of indentation.

type Level = IntSource

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.

showResultSource

Arguments

:: IndentAmt

Indent each level by this many spaces

-> ShowAll

If True, shows all Pdct, even ones where rHide is True. Otherwise, respects rHide and does not show hidden Pdct.

-> 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.

showTopResultSource

Arguments

:: 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 rHide is True. Otherwise, respects rHide and does not show hidden Pdct.

-> 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.

showPdct :: IndentAmt -> Level -> Pdct a -> [Chunk]Source

Shows a Pdct tree without evaluating it.

filter :: Pdct a -> [a] -> [a]Source

verboseFilterSource

Arguments

:: (a -> Text)

How to describe each subject

-> IndentAmt

Indent each level by this many spaces

-> ShowAll

If True, shows all Pdct, even ones where rHide is True. Otherwise, respects rHide and does not show hidden Pdct.

-> 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

compareBySource

Arguments

:: 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.

compareByMaybeSource

Arguments

:: 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.

greaterBySource

Arguments

:: 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 two items

-> Pdct a 

lessBySource

Arguments

:: 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 two items

-> Pdct a 

equalBySource

Arguments

:: 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 two items

-> Pdct a 

greaterEqBySource

Arguments

:: 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 two items

-> Pdct a 

lessEqBySource

Arguments

:: 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 two items

-> Pdct a 

notEqBySource

Arguments

:: 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 two items

-> Pdct a 

Overloaded

compareSource

Arguments

:: (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.

greaterSource

Arguments

:: (Show a, Ord a) 
=> Text

How to show the item being compared; used to describe the Pdct

-> a

The right hand side of the comparison.

-> Pdct a 

lessSource

Arguments

:: (Show a, Ord a) 
=> Text

How to show the item being compared; used to describe the Pdct

-> a

The right hand side of the comparison.

-> Pdct a 

equalSource

Arguments

:: (Show a, Ord a) 
=> Text

How to show the item being compared; used to describe the Pdct

-> a

The right hand side of the comparison.

-> Pdct a 

greaterEqSource

Arguments

:: (Show a, Ord a) 
=> Text

How to show the item being compared; used to describe the Pdct

-> a

The right hand side of the comparison.

-> Pdct a 

lessEqSource

Arguments

:: (Show a, Ord a) 
=> Text

How to show the item being compared; used to describe the Pdct

-> a

The right hand side of the comparison.

-> Pdct a 

notEqSource

Arguments

:: (Show a, Ord a) 
=> Text

How to show the item being compared; used to describe the Pdct

-> a

The right hand side of the comparison.

-> Pdct a 

parseComparerSource

Arguments

:: 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.