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

data Pdct a Source

A tree of predicates.

Constructors

Pdct Label (Node a) 

Instances

Show (Pdct a) 

data Node a Source

Constructors

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.

always :: Pdct aSource

Returns a tree that is always True.

never :: Pdct aSource

Returns a tree that is always False.

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

and :: [Pdct a] -> Pdct aSource

or :: [Pdct a] -> Pdct aSource

not :: Pdct a -> Pdct aSource

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.

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

Forms a Pdct using and.

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

Forms a Pdct using or.

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

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.

type IndentAmt = IntSource

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

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

Shows a Pdct tree without evaluating it.

eval :: Pdct a -> a -> Maybe BoolSource

Evaluates a Pdct.

evaluateSource

Arguments

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

filterSource

Arguments

:: IndentAmt

Indent each level by this many spaces.

-> ShowDiscards

If True, show discarded test results; otherwise, hide them.

-> Level

How many levels deep in the tree we are. Typically you will start at level 0. This determines the level of indentation.

-> (a -> Text)

How to show each item. This is used to add a description of each item to the verbose output. This Text should be a one-line description, without any newlines.

-> Pdct a

Use this Pdct to filter

-> [a]

The list to filter

-> ([a], [Chunk])

The results of the filtering, and the verbose output indicating what was kept and discarded and why

Filters a list of items by including only the ones for which the Pdct returns Just True. Also, renames each top-level Pdct so that the textual results include a description of the item being evaluated.

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 Just True; otherwise it is Just 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; used to describe the Pdct

-> Text

Description of the type of thing that is being matched

-> (a -> Maybe Ordering)

How to compare an item against the right hand side. Return Just LT if the item is less than the right hand side; Just GT if greater; Just EQ if equal to the right hand side. Return Nothing if the item cannot return an item to be compared. The result of the evaluation of the Pdct will then be Nothing.

-> Ordering

When subjects are compared, this ordering must be the result in order for the Pdct to be Just True; otherwise it is Just False, or Nothing if the subject does not return an ordering. The subject will be on the left hand side.

-> Pdct a 

Like compareBy but allows the comparison of items that may fail to return an ordering.

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 Just True; otherwise it is Just 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.