prednote-0.26.0.4: Evaluate and display trees of predicates

Safe HaskellSafe-Inferred
LanguageHaskell2010

Prednote.Core

Description

Pred core functions. If your needs are simple, Prednote.Prebuilt is easier to use. However, the types and functions in this module give you more control.

Each function in this module that returns a Pred returns one with the following characteristics:

Upon evaluation:

Thus, the Pred created by this module are rather bare-bones, but you can modify them as you see fit; Prednote.Prebuilt already does this for you.

This module exports some names that conflict with Prelude names, so you might want to do something like

import qualified Prednote.Pred.Core as P

Synopsis

Documentation

type Chunker = Int -> [Chunk] Source

Indicates how to display text. This function is applied to an Int that is the level of indentation; each level of descent through a tree of Pred increments this Int by one. Because the function returns a list of Chunk, you can use multiple colors. Typically this function will indent text accordingly, with a newline at the end.

data Pred a Source

A rose tree of predicates.

Constructors

Pred 

Fields

static :: Tree Chunker

A tree of static names, allowing you to identify the Pred without applying it to a subject.

evaluate :: a -> Tree Output

Evaluates a Pred by applying it to a subject.

Instances

data Output Source

The result of evaluating a Pred.

Constructors

Output 

Fields

result :: Bool
 
visible :: Visible

Results that are not Visible are not shown by the report function.

short :: Maybe Chunker

Indicates whether there was a short circuit when evaluating this Pred. A short circuit occurs when the Pred does not need to evaluate all of its children in order to reach a result. If Nothing, there was no short circuit; otherwise, this is a Just with a Chunker providing a way to display the short circuit.

dynamic :: Chunker

The dynamic label; this indicates how report will show the Pred to the user after it has been evaluated.

Instances

newtype Visible Source

Is this result visible? If not, report will not show it.

Constructors

Visible 

Fields

unVisible :: Bool
 

all :: [Pred a] -> Pred a Source

No Pred in the list may be False for all to be True. An empty list of Pred yields a Pred that always returns True. May short circuit.

any :: [Pred a] -> Pred a Source

At least one Pred in the list must be True for the resulting Pred to be True. An empty list of Pred yields a Pred that always returns False. May short circuit.

not :: Pred a -> Pred a Source

Negates the child Pred. Never short circuits.

fan Source

Arguments

:: ([Bool] -> (Bool, Visible, Maybe Int))

This function is applied to a list of the result from evaluating the child Pred on each fanout item. The function must return a triple, with the Bool indicating success or failure, Visible for visibility, and Maybe Int to indicate whether a short circuit occurred; this must be Nothing if there was no short circuit, or Just with an Int to indicate a short circuit, with the Int indicating that a short circuit occurred after examining the given number of elements.

The resulting Pred always short circuits if the previous function returns a Just Int with the Int being less than zero. Otherwise, the resulting Pred short circuits if the Int is less than the number of elements returned by the fanout function.

-> (a -> [b])

Fanout function

-> Pred b 
-> Pred a 

Fanout. May short circuit.

fanAll Source

Arguments

:: (a -> [b])

Fanout function

-> Pred b 
-> Pred a 

Fanout all. The resulting Pred is True if no child item returns False; an empty list of child items returns True. May short circuit.

fanAny Source

Arguments

:: (a -> [b])

Fanout function

-> Pred b 
-> Pred a 

Fanout any. The resulting Pred is True if at least one child item returns True; an empty list of child items returns False. May short circuit.

fanAtLeast Source

Arguments

:: Int

Find at least this many. If this number is less than or equal to zero, fanAtLeast will always return True.

-> (a -> [b])

Fanout function

-> Pred b 
-> Pred a 

Fanout at least. The resulting Pred is True if at least the given number of child items return True. May short circuit.

report Source

Arguments

:: Int

Start at this level of indentation.

-> Tree Output 
-> [Chunk] 

Indents and formats output for display.

plan Source

Arguments

:: Int

Start at this level of indentation.

-> Pred a 
-> [Chunk] 

Indents and formats static labels for display. This is a plan for how the Pred would be applied.

test :: Pred a -> a -> Bool Source

Applies a Pred to a single subject and returns the result.

testV :: Pred a -> a -> (Bool, [Chunk]) Source

Like test but also returns the accompanying report.

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

Like filter.

filterV :: Pred a -> [a] -> ([a], [Chunk]) Source

Like filter but also returns a list of report, with one report for each list item.

shorter :: [a] -> [a] -> Bool Source

shorter x y is True if list x is shorter than list y. Lazier than taking the length of each list and comparing the results.