| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Prednote.Core
Contents
- newtype Pred a = Pred (a -> Result)
- predicate :: Show a => Text -> (a -> Bool) -> Pred a
- (&&&) :: Pred a -> Pred a -> Pred a
- (|||) :: Pred a -> Pred a -> Pred a
- not :: Pred a -> Pred a
- switch :: Pred a -> Pred b -> Pred (Either a b)
- any :: Pred a -> Pred [a]
- all :: Pred a -> Pred [a]
- data Nothing
- maybe :: Pred Nothing -> Pred a -> Pred (Maybe a)
- addLabel :: Text -> Pred a -> Pred a
- true :: Show a => Pred a
- false :: Show a => Pred a
- same :: Pred Bool
- test :: Pred a -> a -> Bool
- verboseTest :: Pred a -> a -> ([Chunk], Bool)
- verboseTestStdout :: Pred a -> a -> IO Bool
- newtype Condition = Condition [Chunk]
- newtype Value = Value Text
- newtype Label = Label Text
- data Labeled a = Labeled [Label] a
- data Passed
- data Failed
- newtype Result = Result (Labeled (Either Failed Passed))
- splitResult :: Result -> Either (Labeled Failed) (Labeled Passed)
- resultToChunks :: Result -> [Chunk]
- passedToChunks :: Int -> Labeled Passed -> [Chunk]
- failedToChunks :: Int -> Labeled Failed -> [Chunk]
Predicates and their creation
Predicates. Is an instance of Contravariant, which allows you
to change the type using contramap. Though the constructor is
exported, ordinarily you shouldn't need to use it; other functions
in this module create Pred and manipulate them as needed.
Instances
| Contravariant Pred | |
| Show (Pred a) |
predicate :: Show a => Text -> (a -> Bool) -> Pred a Source
Creates a new Pred. In predicate cond f, cond describes
the condition, while f gives the predicate function. For
example, if f is (> 5), then cond might be "is greater than
5".
Predicate combinators
Primitive combinators
You might consider these combinators to be "primitive" in the
sense that you can build a Pred for any user-defined type by
using these combinators alone, along with contramap. Use
&&&, |||, and contramap to analyze product types. Use switch
and contramap to analyze sum types. For a simple example, see the
source code for maybe, which is a simple sum type. For more
complicated examples, see the source code for any and all, as
a list is a sum type where one of the summands is a (recursive!)
product type.
Convenience combinators
These were written using entirely the "primitive" combinators given above.
Labeling
Constant predicates
Evaluating predicates
verboseTest :: Pred a -> a -> ([Chunk], Bool) Source
verboseTestStdout :: Pred a -> a -> IO Bool Source
Like verboseTest, but results are printed to standard output.
Primarily for use in debugging or in a REPL.
Results and converting them to Chunks
Usually you will not need these functions and types, as the functions and types above should meet most use cases; however, these are here so the test suites can use them, and in case you need them.
Gives additional information about a particular Pred to aid the
user when viewing the output.
Any type that is accompanied by a set of labels.
The result of processing a Pred.
splitResult :: Result -> Either (Labeled Failed) (Labeled Passed) Source
Returns whether this Result failed or passed.
resultToChunks :: Result -> [Chunk] Source
Obtain a list of Chunk describing the evaluation process.
Obtain a list of Chunk describing the evaluation process.