-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Predicates for route definitions. -- -- Provides a definition of a predicate type-class together with several -- concrete implementations which are used to constrain the set of -- possible Snap handlers in a type-safe way. @package snap-predicates @version 0.1.0 module Snap.Predicates.Tutorial module Data.Predicate -- | A Bool-like type where each branch True or False -- carries some meta-data which is threaded through Predicate -- evaluation. data Boolean f t -- | logical False with some meta-data F :: (Maybe f) -> Boolean f t -- | logical True with some meta-data T :: t -> Boolean f t -- | 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. class Predicate p a where type family FVal p type family TVal p apply :: Predicate p a => p -> a -> Boolean (FVal p) (TVal p) -- | A Predicate instance which always returns T with the -- given value as T's meta-data. data Const f t Const :: t -> Const f t -- | A Predicate instance which always returns F with the -- given value as F's meta-data. data Fail f t Fail :: f -> Fail f t -- | 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. data (:|:) a b (:|:) :: a -> b -> :|: a b type (:+:) a b = Either a b -- | A Predicate instance corresponding to the logical OR connective -- of two Predicates. The meta-data of each True branch can -- be of different types. data (:||:) a b (:||:) :: a -> b -> :||: a b -- | Data-type used for tupling-up the results of :&:. data (:*:) a b (:*:) :: a -> b -> :*: a b -- | A Predicate instance corresponding to the logical AND -- connective of two Predicates. data (:&:) a b (:&:) :: a -> b -> :&: a b instance (Eq f, Eq t) => Eq (Boolean f t) instance (Show f, Show t) => Show (Boolean f t) instance (Eq a, Eq b) => Eq (a :*: b) instance (Show a, Show b) => Show (a :*: b) instance (Show a, Show b) => Show (a :&: b) instance (Predicate a c, Predicate b c, FVal a ~ FVal b) => Predicate (a :&: b) c instance (Show a, Show b) => Show (a :||: b) instance (Predicate a c, Predicate b c, FVal a ~ FVal b) => Predicate (a :||: b) c instance (Show a, Show b) => Show (a :|: b) instance (Predicate a c, Predicate b c, TVal a ~ TVal b, FVal a ~ FVal b) => Predicate (a :|: b) c instance Show f => Show (Fail f t) instance Predicate (Fail f t) a instance Show t => Show (Const f t) instance Predicate (Const f t) a instance Alternative (Boolean f) instance Applicative (Boolean f) instance Functor (Boolean f) instance MonadPlus (Boolean f) instance Monad (Boolean f) module Snap.Predicates -- | A Predicate against the Requests Accept header. data Accept Accept :: ByteString -> Accept -- | A Predicate which is true only for Accept: -- application/json. data AcceptJson AcceptJson :: AcceptJson -- | A Predicate which is true only for Accept: -- application/x-thrift. data AcceptThrift AcceptThrift :: AcceptThrift -- | A Predicate looking for some parameter value. data Param Param :: ByteString -> Param instance Eq Accept instance Eq AcceptJson instance Eq AcceptThrift instance Eq Param instance Show Param instance Predicate Param Request instance Show AcceptThrift instance Predicate AcceptThrift Request instance Show AcceptJson instance Predicate AcceptJson Request instance Show Accept instance Predicate Accept Request module Snap.Routes data Routes m a -- | Turn route definitions into a list of Strings. showRoutes :: Routes m () -> [String] -- | Turn route definitions into snapable format, i.e. Routes are -- grouped per path and selection evaluates routes against the given Snap -- Request. expandRoutes :: MonadSnap m => Routes m () -> [(ByteString, m ())] get :: (MonadSnap m, Show p, Predicate p Request, FVal p ~ Error) => ByteString -> (TVal p -> m ()) -> p -> Routes m () head :: (MonadSnap m, Show p, Predicate p Request, FVal p ~ Error) => ByteString -> (TVal p -> m ()) -> p -> Routes m () addRoute :: (MonadSnap m, Show p, Predicate p Request, FVal p ~ Error) => Method -> ByteString -> (TVal p -> m ()) -> p -> Routes m () post :: (MonadSnap m, Show p, Predicate p Request, FVal p ~ Error) => ByteString -> (TVal p -> m ()) -> p -> Routes m () put :: (MonadSnap m, Show p, Predicate p Request, FVal p ~ Error) => ByteString -> (TVal p -> m ()) -> p -> Routes m () delete :: (MonadSnap m, Show p, Predicate p Request, FVal p ~ Error) => ByteString -> (TVal p -> m ()) -> p -> Routes m () trace :: (MonadSnap m, Show p, Predicate p Request, FVal p ~ Error) => ByteString -> (TVal p -> m ()) -> p -> Routes m () options :: (MonadSnap m, Show p, Predicate p Request, FVal p ~ Error) => ByteString -> (TVal p -> m ()) -> p -> Routes m () connect :: (MonadSnap m, Show p, Predicate p Request, FVal p ~ Error) => ByteString -> (TVal p -> m ()) -> p -> Routes m () instance Monad (Routes m)