wai-routing-0.3: Declarative routing for WAI.

Safe HaskellSafe-Inferred

Network.Wai.Routing.Predicate.Predicate

Synopsis

Documentation

type Delta = DoubleSource

Delta is a measure of distance. It is (optionally) used in predicates that evaluate to T but not uniquely so, i.e. different evaluations of T are possible and they may have a different "fitness".

An example is content-negotiation. A HTTP request may specify a preference list of various media-types. A predicate matching one specific media-type evaluates to T, but other media-types may match even better. To represent this ambivalence, the predicate will include a delta value which can be used to decide which of the matching predicates should be preferred.

data Boolean f t Source

A Bool-like type where each branch True or False carries some meta-data which is threaded through Predicate evaluation.

Constructors

F f

logical False with some meta-data

T Delta t

logical True with some meta-data

Instances

(Eq f, Eq t) => Eq (Boolean f t) 
(Show f, Show t) => Show (Boolean f t) 

class Predicate p a whereSource

The Predicate class declares the function apply which evaluates the predicate against some value, returning a value of type Boolean. Besides being parameterised over predicate type and predicate parameter, the class is also parameterised over the actual types of T's and F's meta-data.

Associated Types

type FVal p Source

type TVal p Source

Methods

apply :: p -> a -> Boolean (FVal p) (TVal p)Source

Instances

data a :|: b Source

A Predicate instance corresponding to the logical OR connective of two Predicates. It requires the meta-data of each True branch to be of the same type.

If both arguments evaluate to T the one with the smaller Delta will be preferred, or--if equal--the left-hand argument.

Constructors

a :|: b 

Instances

(Predicate a c, Predicate b c, ~ * (TVal a) (TVal b), ~ * (FVal a) (FVal b)) => Predicate (:|: a b) c 

data a :&: b Source

A Predicate instance corresponding to the logical AND connective of two Predicates.

Constructors

a :&: b 

Instances

(Predicate a c, Predicate b c, ~ * (FVal a) (FVal b)) => Predicate (:&: a b) c 

data a :||: b Source

A Predicate instance corresponding to the logical OR connective of two Predicates. The meta-data of each True branch can be of different types.

If both arguments evaluate to T the one with the smaller Delta will be preferred, or--if equal--the left-hand argument.

Constructors

a :||: b 

Instances

(Predicate a c, Predicate b c, ~ * (FVal a) (FVal b)) => Predicate (:||: a b) c 

data a ::: b Source

Data-type used for tupling-up the results of :&:.

Constructors

a ::: b 

Instances

(Eq a, Eq b) => Eq (::: a b) 
(Show a, Show b) => Show (::: a b) 

type :+: a b = Either a bSource

data Const f t Source

A Predicate instance which always returns T with the given value as T's meta-data.

Instances

Predicate (Const f t) a 

data Fail f t Source

A Predicate instance which always returns F with the given value as F's meta-data.

Instances

Predicate (Fail f t) a 

data Opt a Source

A Predicate modifier which makes the underlying predicate optional, i.e. the TVal becomes a Maybe and in the failure-case Nothing is returned.

Instances

Predicate a b => Predicate (Opt a) b 

data Def d a Source

A Predicate modifier which returns as TVal the provided default value if the underlying predicate fails.

Instances

(Predicate a b, ~ * d (TVal a)) => Predicate (Def d a) b 

data PMap a f t Source

A Predicate function, i.e. a function of the underlying predicate's result.

Instances

Predicate a b => Predicate (PMap a f t) b 

data PMapT a t Source

Like PMap but a function of the underlying predicate's TVal.

Instances

Predicate a b => Predicate (PMapT a t) b 

data PMapF a f Source

Like PMap but a function of the underlying predicate's FVal.

Instances

Predicate a b => Predicate (PMapF a f) b 

constant :: t -> Const f tSource

failure :: f -> Fail f tSource

opt :: a -> Opt aSource

def :: d -> a -> Def d aSource

pmap :: (Boolean (FVal a) (TVal a) -> Boolean f t) -> a -> PMap a f tSource

pmapT :: (TVal a -> Boolean (FVal a) t) -> a -> PMapT a tSource

pmapF :: (FVal a -> Boolean f (TVal a)) -> a -> PMapF a fSource

with :: (Monad m, Predicate p a) => p -> a -> (TVal p -> m ()) -> m ()Source

The with function will invoke the given function only if the predicate p applied to the test value a evaluates to T.