| Copyright | (C) 2014-15 Mark Andrus Roberts |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Mark Andrus Roberts <markandrusroberts@gmail.com> |
| Stability | provisional |
| Safe Haskell | None |
| Language | Haskell98 |
Text.XML.Twiml.Internal
Description
This module exports the machinery necessary to define TwiML in an extensible way.
- data (f :+: g) a
- class (Functor sub, Functor sup) => sub :<: sup where
- type family Elem t ts :: Bool
- type (∉) t ts = Elem t ts ~ False
- class Functor1 f where
- fmap1 :: (a -> b) -> f i a -> f i b
- class NFData1 f where
- class Show1 f where
- class Functor1 f => IxApplicative f where
- class IxApplicative m => IxMonad m where
- data IxFree f i a where
- iliftF :: forall f i a. (WitnessList i, Functor1 f) => f i a -> IxFree f i a
- type family a ++ b :: [k]
- data SomeNode = forall n . Node n => SomeNode n
- class ToSomeNode a where
- toSomeNode :: a -> SomeNode
- class ToXML a where
- toXML :: a -> [Element]
- class ToElement a where
- toElement :: a -> Element
- class ToAttrs a where
- toAttrs :: a -> [Attr]
- class ToAttrValue a where
- toAttrValue :: a -> String
- 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
Data types à la carte
The ( data type and :+:)( type class come from
Swierstra's
Data types à la carte.:<:)
data (f :+: g) a infixr 7
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
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 (∉)
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.
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 Functor1 f where
Methods
fmap1 :: (a -> b) -> f i a -> f i b
Instances
| Functor1 [*] ClientF | |
| Functor1 [*] ConferenceF | |
| Functor1 [*] NumberF | |
| Functor1 [*] QueueF | |
| Functor1 [*] DialNounF | |
| Functor1 [*] SipF | |
| Functor1 [*] DialF | |
| Functor1 [*] EndF | |
| Functor1 [*] EnqueueF | |
| Functor1 [*] HangupF | |
| Functor1 [*] LeaveF | |
| Functor1 [*] MessageF | |
| Functor1 [*] PauseF | |
| Functor1 [*] PlayF | |
| Functor1 [*] RecordF | |
| Functor1 [*] RedirectF | |
| Functor1 [*] RejectF | |
| Functor1 [*] SayF | |
| Functor1 [*] MessagingVerbsF | |
| Functor1 [*] VoiceVerbsF | |
| Functor1 [*] GatherF | |
| Functor1 [*] SmsF | |
| Functor1 [k] f => Functor1 [k] (IxFree k f) |
class NFData1 f where
class Show1 f where
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 ::IxApplicativef -> a -> fIdentitya pure =ipure(<*>) ::IxApplicativef => f i (a -> b) -> f j a -> f (i<>j) b (<*>) =iap
Methods
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.
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
XML
The classes here simplify working with the xml package.
class ToSomeNode a where
Methods
toSomeNode :: a -> SomeNode
Instances
| ToSomeNode String | |
| ToSomeNode () | |
| ToSomeNode URL | |
| ToSomeNode DialNoun | |
| ToSomeNode a => ToSomeNode (Maybe a) |
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 ToAttrs a where
Methods
toAttrs :: a -> [Attr]
Instances
class ToAttrValue a where
toAttrValue transforms a data type into a String that can be set as the
value of an attribute.
Methods
toAttrValue :: a -> String
makeAttr :: ToAttrValue b => String -> (a -> Maybe b) -> a -> Maybe Attr
makeElement :: Node t => String -> t -> [Attr] -> Element