twiml-0.2.0.0: TwiML library for Haskell

Copyright(C) 2014-15 Mark Andrus Roberts
LicenseBSD-style (see the file LICENSE)
MaintainerMark Andrus Roberts <markandrusroberts@gmail.com>
Stabilityprovisional
Safe HaskellNone
LanguageHaskell98

Text.XML.Twiml.Internal

Contents

Description

This module exports the machinery necessary to define TwiML in an extensible way.

Synopsis

Data types à la carte

The (:+:) data type and (:<:) type class come from Swierstra's Data types à la carte.

data (f :+: g) a infixr 7 Source

Constructors

InL (f a) 
InR (g a) 

Instances

(Functor f, Functor g, Functor h, (:<:) f g) => f :<: ((:+:) * h g) Source 
(Functor f, Functor g) => f :<: ((:+:) * f g) Source 
(Functor f, Functor g) => Functor ((:+:) * f g) Source 
(Eq (f a), Eq (g a)) => Eq ((:+:) k f g a) Source 
(Data a, Data (f a), Data (g a), Typeable (* -> *) f, Typeable (* -> *) g) => Data ((:+:) * f g a) Source 
(Ord (f a), Ord (g a)) => Ord ((:+:) k f g a) Source 
(Read (f a), Read (g a)) => Read ((:+:) k f g a) Source 
(Show (f a), Show (g a)) => Show ((:+:) k f g a) Source 
Generic ((:+:) k f g a) Source 
(NFData (f a), NFData (g a)) => NFData ((:+:) k f g a) Source 
(ToXML (f a), ToXML (g a)) => ToXML ((:+:) k f g a) Source 
type Rep ((:+:) k f g a) Source 

class (Functor sub, Functor sup) => sub :<: sup where Source

Methods

inj :: sub a -> sup a Source

prj :: sup a -> Maybe (sub a) Source

Instances

Functor f => f :<: f Source 
(Functor f, Functor g, Functor h, (:<:) f g) => f :<: ((:+:) * h g) Source 
(Functor f, Functor g) => f :<: ((:+:) * f g) Source 
(:<:) (f i) ((:+:) * (ClientF i) ((:+:) * (ConferenceF i) ((:+:) * (NumberF i) ((:+:) * (QueueF i) (SipF i))))) => (f i) :<: (DialNounF i) Source 
(:<:) (f i) ((:+:) * (MessageF i) ((:+:) * (RedirectF i) ((:+:) * (SmsF i) (EndF i)))) => (f i) :<: (MessagingVerbsF i) Source 
(:<:) (f i) ((:+:) * (SayF i) ((:+:) * (PlayF i) ((:+:) * (GatherF i) ((:+:) * (SmsF i) ((:+:) * (DialF i) ((:+:) * (EnqueueF i) ((:+:) * (LeaveF i) ((:+:) * (HangupF i) ((:+:) * (RecordF i) ((:+:) * (RedirectF i) ((:+:) * (RejectF i) ((:+:) * (PauseF i) (EndF i))))))))))))) => (f i) :<: (VoiceVerbsF i) Source 

Elem (∉)

type family Elem t ts :: Bool Source

Elem is like a promoted elem: it allows us to check whether a type constructor t is present in a list of type constructors ts.

Equations

Elem t `[]` = False 
Elem t (t : ts) = True 
Elem t (u : ts) = Elem t ts 

type (∉) t ts = Elem t ts ~ False Source

t ∉ ts is shorthand for asserting that a type constructor t is not present in a list of types constructors ts.

Indexed

Everything in this section comes from Cirdec's excellent answer on a StackOverflow question about indexed free monads. Some names have been changed to follow the patterns established by indexed and indexed-free.

class NFData1 f where Source

Methods

rnf1 :: NFData a => f i a -> () Source

Instances

NFData1 [k] f => NFData1 [k] (IxFree k f) Source 

class Show1 f where Source

Methods

show1 :: Show a => f i a -> String Source

Applicative

class Functor1 f => IxApplicative f where Source

An applicative functor f indexed by a monoid (M,<>,Identity)

If you import Prelude hiding (<*>) and pure, you can redefine (<*>) and pure to use their indexed equivalents. For example,

import Prelude hiding ((<*>), pure)

pure :: IxApplicative f -> a -> f Identity a
pure = ipure

(<*>) :: IxApplicative f => f i (a -> b) -> f j a -> f (i <> j) b
(<*>) = iap

Associated Types

type Identity :: k Source

type i <> j :: k Source

Methods

ipure :: a -> f Identity a Source

The indexed equivalent of pure

iap :: f i (a -> b) -> f j a -> f (i <> j) b Source

The indexed equivalent of (<*>)

Instances

Functor1 [k] f => IxApplicative [k] (IxFree k f) Source 

Monad

class IxApplicative m => IxMonad m where Source

A monad m indexed by a monoid (M,<>,Identity)

You can use do-notation with IxMonad by enabling the RebindableSyntax extension and redefining (>>=), (>>), and return. For example,

{-#LANGUAGE RebindableSyntax #-}

import Prelude hiding ((>>=), (>>), return)

(>>=) :: IxMonad m => m i a -> (a -> m j b) -> m (i <> j) b
(>>=) = ibind

(>>) :: IxMonad m => m i a -> m j b -> m (i <> j) b
a >> b = a >>= const b

return :: IxApplicative m => a -> m Identity a
return = ipure

This is the technique employed by the Text.XML.Twiml.Syntax module.

Methods

ibind :: m i a -> (a -> m j b) -> m (i <> j) b Source

The indexed equivalent of (>>=)

Instances

(Functor1 [k] m, IxApplicative [k] (IxFree k m)) => IxMonad [k] (IxFree k m) Source 

Free

data IxFree f i a where Source

A free monad indexed by a monoid (M,++,[])

Constructors

IxPure :: a -> IxFree f `[]` a 
IxFree :: WitnessList i => f i (IxFree f j a) -> IxFree f (i ++ j) a 

Instances

NFData1 [k] f => NFData1 [k] (IxFree k f) Source 
(Functor1 [k] m, IxApplicative [k] (IxFree k m)) => IxMonad [k] (IxFree k m) Source 
Functor1 [k] f => IxApplicative [k] (IxFree k f) Source 
Show1 [k] f => Show1 [k] (IxFree k f) Source 
Functor1 [k] f => Functor1 [k] (IxFree k f) Source 
Functor1 [k] f => Functor (IxFree k f i) Source 
(Show1 [k] f, Show a) => Show (IxFree k f i a) Source 
(NFData1 [k] f, NFData a) => NFData (IxFree k f i a) Source 
ToXML (IxFree * DialNounF i Void) Source 
ToXML (IxFree * MessagingVerbsF i Void) Source 
ToXML (IxFree * VoiceVerbsF i Void) Source 

iliftF :: forall f i a. (WitnessList i, Functor1 f) => f i a -> IxFree f i a Source

Lift an indexed functor into IxFree

type family a ++ b :: [k] Source

Promoted list concatenation

Equations

`[]` ++ bs = bs 
(a : as) ++ bs = a : (as ++ bs) 

XML

The classes here simplify working with the xml package.

data SomeNode Source

Constructors

forall n . Node n => SomeNode n 

Instances

makeAttr :: ToAttrValue b => String -> (a -> Maybe b) -> a -> Maybe Attr Source

makeAttr' :: String -> (a -> Maybe b) -> (b -> String) -> a -> Maybe Attr Source

makeAttrs :: a -> [a -> Maybe Attr] -> [Attr] Source

makeElement :: Node t => String -> t -> [Attr] -> Element Source