| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Prednote
Description
This module provides everything you need for most uses of Prednote.
The core type of Prednote is the Pred, which is a rose
Tree of predicates along with some additional information, such
as a plan, which shows you how the Pred will be evaluated
without actually having to apply it to a particular subject. When
evaluating a Pred, you can also display a report describing the
evaluation process.
This module builds Pred with reports that make sparing use of
color; for example, True results have [TRUE] indicated in
green, [FALSE] in red, and short circuits (that is, Pred that
were evaluated without evaluating all their child Pred) indicated
in yellow. They are also nicely indented to indicate the structure
of the Tree.
If you want more control over how your results are formatted,
examine Prednote.Core and Prednote.Format.
Prednote.Comparisons builds on this module to provide Pred to
use for common comparisons (such as greater than, less than, etc.)
Prednote.Expressions helps you parse infix or postfix (i.e. RPN)
expressions.
This module exports some names that conflict with Prelude names, so you might want to do something like
import qualified Prednote as P
- data Pred a
- data Visible
- shown :: Visible
- hidden :: Visible
- visibility :: (Bool -> Visible) -> Pred a -> Pred a
- reveal :: Pred a -> Pred a
- hide :: Pred a -> Pred a
- showTrue :: Pred a -> Pred a
- showFalse :: Pred a -> Pred a
- predicate :: Text -> (a -> Text) -> (a -> Bool) -> Pred a
- true :: Pred a
- false :: Pred a
- same :: Pred Bool
- all :: [Pred a] -> Pred a
- (&&&) :: Pred a -> Pred a -> Pred a
- any :: [Pred a] -> Pred a
- (|||) :: Pred a -> Pred a -> Pred a
- not :: Pred a -> Pred a
- wrap :: Text -> (a -> Text) -> (a -> b) -> Pred b -> Pred a
- fanAll :: (a -> [b]) -> Pred b -> Pred a
- fanAny :: (a -> [b]) -> Pred b -> Pred a
- fanAtLeast :: Int -> (a -> [b]) -> Pred b -> Pred a
- data Output
- plan :: Pred a -> [Chunk]
- evaluate :: Pred a -> a -> Tree Output
- report :: Tree Output -> [Chunk]
- test :: Pred a -> a -> Bool
- testV :: Pred a -> a -> (Bool, [Chunk])
- filter :: Pred a -> [a] -> [a]
- filterV :: Pred a -> [a] -> ([a], [Chunk])
Pred
Visibility
Upon evaluation, each Pred has a visibility, indicated with
Visible. It can be either shown or hidden. The
visibility of a Pred does not affect any of the results, nor
does it affect how the Pred is shown in the plan; rather,
it affects only how the result of the Pred is shown in the
report. If a Pred is hidden, its value and the value of
its children is not shown in the report.
Is this result visible? If not, report will not show it.
Arguments
| :: (Bool -> Visible) | When applied to the |
| -> Pred a | |
| -> Pred a |
Creates a Pred with its visibility modified.
Predicates
Arguments
| :: Text | Static label |
| -> (a -> Text) | Computes the dynamic label. Do not indicate whether the result
is |
| -> (a -> Bool) | Predicate function |
| -> Pred a |
Builds predicates.
Combinators
These functions combine one more more Pred to create a new
Pred; the argument Pred become children of the new Pred.
Fanout
These functions allow you to take a single subject and split it
into multiple subjects, applying a Pred to each subject that
results. As a simple example, this allows you to build a Pred
[Int] that combines Pred that test individual Int along
with Pred that examine the entire list of [Int].
fanAtLeast :: Int -> (a -> [b]) -> Pred b -> Pred a Source
At least the given number of child items must be True.
Reports and plans
A plan displays a Pred without evaluating it, while a
report shows the process through which a Pred was evaluated
for a particular subject.