Safe Haskell | None |
---|---|
Language | Haskell2010 |
- newtype PredM f a = PredM {}
- type Pred = PredM Identity
- predicate :: (a -> (Bool, Value, Condition)) -> Pred a
- predicateM :: Functor f => (a -> f (Bool, Value, Condition)) -> PredM f a
- contramapM :: Monad m => (a -> m b) -> PredM m b -> PredM m a
- (&&&) :: Monad m => PredM m a -> PredM m a -> PredM m a
- (|||) :: Monad m => PredM m a -> PredM m a -> PredM m a
- not :: Functor m => PredM m a -> PredM m a
- switch :: PredM m a -> PredM m b -> PredM m (Either a b)
- any :: (Monad m, Applicative m) => PredM m a -> PredM m [a]
- all :: (Monad m, Applicative m) => PredM m a -> PredM m [a]
- maybe :: Applicative m => Bool -> PredM m a -> PredM m (Maybe a)
- addLabel :: Functor f => [Chunk Text] -> PredM f a -> PredM f a
- true :: Applicative f => PredM f a
- false :: Applicative f => PredM f a
- same :: Applicative f => PredM f Bool
- test :: Pred a -> a -> Bool
- testM :: Functor f => PredM f a -> a -> f Bool
- runPred :: Pred a -> a -> Result
- verboseTest :: Pred a -> a -> ([Chunk Text], Bool)
- verboseTestStdout :: Pred a -> a -> IO Bool
- newtype Condition = Condition [Chunk Text]
- newtype Value = Value [Chunk Text]
- newtype Label = Label [Chunk 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 Text]
- passedToChunks :: Int -> Labeled Passed -> [Chunk Text]
- failedToChunks :: Int -> Labeled Failed -> [Chunk Text]
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 PredM
and manipulate them as needed.
The f
type variable is an arbitrary context; ordinarily this type
will be an instance of Monad
, and some of the bindings in this
module require this. That allows you to run predicate computations
that run in some sort of context, allowing you to perform IO,
examine state, or whatever. If you only want to do pure
computations, just use the Pred
type synonym.
Contravariant (PredM f) | |
Show (PredM f a) |
predicate :: (a -> (Bool, Value, Condition)) -> Pred a Source
Creates a new Pred
that do not run in any context. 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"
.
predicateM :: Functor f => (a -> f (Bool, Value, Condition)) -> PredM f a Source
Creates a new PredM
that run in some arbitrary context. In
predicateM 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"
.
contramapM :: Monad m => (a -> m b) -> PredM m b -> PredM m a Source
Like contramap
but allows the mapping function to run in a
monad.
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
true :: Applicative f => PredM f a Source
Always returns True
false :: Applicative f => PredM f a Source
Always returns False
same :: Applicative f => PredM f Bool Source
Always returns its argument
Evaluating predicates
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 Chunk
s
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.
Stores the representation of a value.
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 Text] Source
Obtain a list of Chunk
describing the evaluation process.
Obtain a list of Chunk
describing the evaluation process.