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

Constructors

InL (f a) 
InR (g a) 

Instances

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

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

Methods

inj :: sub a -> sup a

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

Instances

Functor f => f :<: f 
(Functor f, Functor g, Functor h, (:<:) f g) => f :<: ((:+:) * h g) 
(Functor f, Functor g) => f :<: ((:+:) * f g) 
(:<:) (f i) ((:+:) * (ClientF i) ((:+:) * (ConferenceF i) ((:+:) * (NumberF i) ((:+:) * (QueueF i) (SipF i))))) => (f i) :<: (DialNounF i) 
(:<:) (f i) ((:+:) * (MessageF i) ((:+:) * (RedirectF i) ((:+:) * (SmsF i) (EndF i)))) => (f i) :<: (MessagingVerbsF i) 
(:<:) (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) 

Elem (∉)

type family Elem t ts :: Bool

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

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

Methods

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

Instances

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

class Show1 f where

Methods

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

Instances

Show1 [*] DialNounF 
Show1 [*] MessagingVerbsF 
Show1 [*] VoiceVerbsF 
Show1 [k] f => Show1 [k] (IxFree k f) 

Applicative

class Functor1 f => IxApplicative f where

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

type i <> j :: k

Methods

ipure :: a -> f Identity a

The indexed equivalent of pure

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

The indexed equivalent of (<*>)

Instances

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

Monad

class IxApplicative m => IxMonad m where

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

The indexed equivalent of (>>=)

Instances

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

Free

data IxFree f i a where

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) 
(Functor1 [k] m, IxApplicative [k] (IxFree k m)) => IxMonad [k] (IxFree k m) 
Functor1 [k] f => IxApplicative [k] (IxFree k f) 
Show1 [k] f => Show1 [k] (IxFree k f) 
Functor1 [k] f => Functor1 [k] (IxFree k f) 
Functor1 [k] f => Functor (IxFree k f i) 
(Show1 [k] f, Show a) => Show (IxFree k f i a) 
(NFData1 [k] f, NFData a) => NFData (IxFree k f i a) 
ToXML (IxFree * DialNounF i Void) 
ToXML (IxFree * MessagingVerbsF i Void) 
ToXML (IxFree * VoiceVerbsF i Void) 

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

Lift an indexed functor into IxFree

type family a ++ b :: [k]

Promoted list concatenation

Equations

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

XML

The classes here simplify working with the xml package.

data SomeNode

Constructors

forall n . Node n => SomeNode n 

Instances

Node SomeNode 

class ToXML a where

Methods

toXML :: a -> [Element]

Instances

ToXML DialNoun 
ToXML (ClientF i a) 
ToXML (ConferenceF i a) 
ToXML (NumberF i a) 
ToXML (QueueF i a) 
ToXML a => ToXML (DialNounF i a) 
ToXML (SipF i a) 
ToXML a => ToXML (DialF i a) 
ToXML (EndF i a) 
ToXML a => ToXML (EnqueueF i a) 
ToXML (HangupF i a) 
ToXML (LeaveF i a) 
ToXML a => ToXML (MessageF i a) 
ToXML a => ToXML (PauseF i a) 
ToXML a => ToXML (PlayF i a) 
ToXML a => ToXML (RecordF i a) 
ToXML (RedirectF i a) 
ToXML (RejectF i a) 
ToXML a => ToXML (SayF i a) 
ToXML a => ToXML (MessagingVerbsF i a) 
ToXML a => ToXML (VoiceVerbsF i a) 
ToXML a => ToXML (GatherF i a) 
ToXML a => ToXML (SmsF i a) 
ToXML (IxFree * DialNounF i Void) 
ToXML (IxFree * MessagingVerbsF i Void) 
ToXML (IxFree * VoiceVerbsF i Void) 
(ToXML (f a), ToXML (g a)) => ToXML ((:+:) k f g a) 

class ToElement a where

Methods

toElement :: a -> Element

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

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

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

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