    {-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, OverlappingInstances, MultiParamTypeClasses, TypeFamilies #-}
    module HSP.Monad where

    import Control.Applicative  (Applicative, Alternative, (<$>))
    import Control.Monad        (MonadPlus)
    import Control.Monad.Cont   (MonadCont)
    import Control.Monad.Error  (MonadError)
    import Control.Monad.Fix    (MonadFix)
    import Control.Monad.Reader (MonadReader)
    import Control.Monad.Writer (MonadWriter)
    import Control.Monad.State  (MonadState)
    import Control.Monad.Trans  (MonadIO, MonadTrans(lift))
    import Data.String          (fromString)
    import qualified Data.Text  as Strict
    import Data.Text.Lazy       (Text)
    import qualified Data.Text.Lazy as Lazy
    import HSP.XMLGenerator     (AppendChild(..), Attr(..), EmbedAsAttr(..), EmbedAsChild(..), IsName(..), SetAttr(..), XMLGen(..), XMLGenerator)
    import HSP.XML              (Attribute(..), XML(..), AttrValue(..), pAttrVal, pcdata)

    newtype HSPT xml m a = HSPT { forall xml (m :: * -> *) a. HSPT xml m a -> m a
    unHSPT :: m a }
        deriving ((forall a b. (a -> b) -> HSPT xml m a -> HSPT xml m b)
    -> (forall a b. a -> HSPT xml m b -> HSPT xml m a)
    -> Functor (HSPT xml m)
    forall a b. a -> HSPT xml m b -> HSPT xml m a
    forall a b. (a -> b) -> HSPT xml m a -> HSPT xml m b
    forall xml (m :: * -> *) a b.
    Functor m =>
    a -> HSPT xml m b -> HSPT xml m a
    forall xml (m :: * -> *) a b.
    Functor m =>
    (a -> b) -> HSPT xml m a -> HSPT xml m b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    $cfmap :: forall xml (m :: * -> *) a b.
    Functor m =>
    (a -> b) -> HSPT xml m a -> HSPT xml m b
    fmap :: forall a b. (a -> b) -> HSPT xml m a -> HSPT xml m b
    $c<$ :: forall xml (m :: * -> *) a b.
    Functor m =>
    a -> HSPT xml m b -> HSPT xml m a
    <$ :: forall a b. a -> HSPT xml m b -> HSPT xml m a
    Functor, Functor (HSPT xml m)
    Functor (HSPT xml m)
    -> (forall a. a -> HSPT xml m a)
    -> (forall a b.
        HSPT xml m (a -> b) -> HSPT xml m a -> HSPT xml m b)
    -> (forall a b c.
        (a -> b -> c) -> HSPT xml m a -> HSPT xml m b -> HSPT xml m c)
    -> (forall a b. HSPT xml m a -> HSPT xml m b -> HSPT xml m b)
    -> (forall a b. HSPT xml m a -> HSPT xml m b -> HSPT xml m a)
    -> Applicative (HSPT xml m)
    forall a. a -> HSPT xml m a
    forall a b. HSPT xml m a -> HSPT xml m b -> HSPT xml m a
    forall a b. HSPT xml m a -> HSPT xml m b -> HSPT xml m b
    forall a b. HSPT xml m (a -> b) -> HSPT xml m a -> HSPT xml m b
    forall a b c.
    (a -> b -> c) -> HSPT xml m a -> HSPT xml m b -> HSPT xml m c
    forall {xml} {m :: * -> *}. Applicative m => Functor (HSPT xml m)
    forall xml (m :: * -> *) a. Applicative m => a -> HSPT xml m a
    forall xml (m :: * -> *) a b.
    Applicative m =>
    HSPT xml m a -> HSPT xml m b -> HSPT xml m a
    forall xml (m :: * -> *) a b.
    Applicative m =>
    HSPT xml m a -> HSPT xml m b -> HSPT xml m b
    forall xml (m :: * -> *) a b.
    Applicative m =>
    HSPT xml m (a -> b) -> HSPT xml m a -> HSPT xml m b
    forall xml (m :: * -> *) a b c.
    Applicative m =>
    (a -> b -> c) -> HSPT xml m a -> HSPT xml m b -> HSPT xml m c
    forall (f :: * -> *).
    Functor f
    -> (forall a. a -> f a)
    -> (forall a b. f (a -> b) -> f a -> f b)
    -> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
    -> (forall a b. f a -> f b -> f b)
    -> (forall a b. f a -> f b -> f a)
    -> Applicative f
    $cpure :: forall xml (m :: * -> *) a. Applicative m => a -> HSPT xml m a
    pure :: forall a. a -> HSPT xml m a
    $c<*> :: forall xml (m :: * -> *) a b.
    Applicative m =>
    HSPT xml m (a -> b) -> HSPT xml m a -> HSPT xml m b
    <*> :: forall a b. HSPT xml m (a -> b) -> HSPT xml m a -> HSPT xml m b
    $cliftA2 :: forall xml (m :: * -> *) a b c.
    Applicative m =>
    (a -> b -> c) -> HSPT xml m a -> HSPT xml m b -> HSPT xml m c
    liftA2 :: forall a b c.
    (a -> b -> c) -> HSPT xml m a -> HSPT xml m b -> HSPT xml m c
    $c*> :: forall xml (m :: * -> *) a b.
    Applicative m =>
    HSPT xml m a -> HSPT xml m b -> HSPT xml m b
    *> :: forall a b. HSPT xml m a -> HSPT xml m b -> HSPT xml m b
    $c<* :: forall xml (m :: * -> *) a b.
    Applicative m =>
    HSPT xml m a -> HSPT xml m b -> HSPT xml m a
    <* :: forall a b. HSPT xml m a -> HSPT xml m b -> HSPT xml m a
    Applicative, Applicative (HSPT xml m)
    Applicative (HSPT xml m)
    -> (forall a. HSPT xml m a)
    -> (forall a. HSPT xml m a -> HSPT xml m a -> HSPT xml m a)
    -> (forall a. HSPT xml m a -> HSPT xml m [a])
    -> (forall a. HSPT xml m a -> HSPT xml m [a])
    -> Alternative (HSPT xml m)
    forall a. HSPT xml m a
    forall a. HSPT xml m a -> HSPT xml m [a]
    forall a. HSPT xml m a -> HSPT xml m a -> HSPT xml m a
    forall {xml} {m :: * -> *}.
    Alternative m =>
    Applicative (HSPT xml m)
    forall xml (m :: * -> *) a. Alternative m => HSPT xml m a
    forall xml (m :: * -> *) a.
    Alternative m =>
    HSPT xml m a -> HSPT xml m [a]
    forall xml (m :: * -> *) a.
    Alternative m =>
    HSPT xml m a -> HSPT xml m a -> HSPT xml m a
    forall (f :: * -> *).
    Applicative f
    -> (forall a. f a)
    -> (forall a. f a -> f a -> f a)
    -> (forall a. f a -> f [a])
    -> (forall a. f a -> f [a])
    -> Alternative f
    $cempty :: forall xml (m :: * -> *) a. Alternative m => HSPT xml m a
    empty :: forall a. HSPT xml m a
    $c<|> :: forall xml (m :: * -> *) a.
    Alternative m =>
    HSPT xml m a -> HSPT xml m a -> HSPT xml m a
    <|> :: forall a. HSPT xml m a -> HSPT xml m a -> HSPT xml m a
    $csome :: forall xml (m :: * -> *) a.
    Alternative m =>
    HSPT xml m a -> HSPT xml m [a]
    some :: forall a. HSPT xml m a -> HSPT xml m [a]
    $cmany :: forall xml (m :: * -> *) a.
    Alternative m =>
    HSPT xml m a -> HSPT xml m [a]
    many :: forall a. HSPT xml m a -> HSPT xml m [a]
    Alternative, Applicative (HSPT xml m)
    Applicative (HSPT xml m)
    -> (forall a b.
        HSPT xml m a -> (a -> HSPT xml m b) -> HSPT xml m b)
    -> (forall a b. HSPT xml m a -> HSPT xml m b -> HSPT xml m b)
    -> (forall a. a -> HSPT xml m a)
    -> Monad (HSPT xml m)
    forall a. a -> HSPT xml m a
    forall a b. HSPT xml m a -> HSPT xml m b -> HSPT xml m b
    forall a b. HSPT xml m a -> (a -> HSPT xml m b) -> HSPT xml m b
    forall {xml} {m :: * -> *}. Monad m => Applicative (HSPT xml m)
    forall xml (m :: * -> *) a. Monad m => a -> HSPT xml m a
    forall xml (m :: * -> *) a b.
    Monad m =>
    HSPT xml m a -> HSPT xml m b -> HSPT xml m b
    forall xml (m :: * -> *) a b.
    Monad m =>
    HSPT xml m a -> (a -> HSPT xml m b) -> HSPT xml m b
    forall (m :: * -> *).
    Applicative m
    -> (forall a b. m a -> (a -> m b) -> m b)
    -> (forall a b. m a -> m b -> m b)
    -> (forall a. a -> m a)
    -> Monad m
    $c>>= :: forall xml (m :: * -> *) a b.
    Monad m =>
    HSPT xml m a -> (a -> HSPT xml m b) -> HSPT xml m b
    >>= :: forall a b. HSPT xml m a -> (a -> HSPT xml m b) -> HSPT xml m b
    $c>> :: forall xml (m :: * -> *) a b.
    Monad m =>
    HSPT xml m a -> HSPT xml m b -> HSPT xml m b
    >> :: forall a b. HSPT xml m a -> HSPT xml m b -> HSPT xml m b
    $creturn :: forall xml (m :: * -> *) a. Monad m => a -> HSPT xml m a
    return :: forall a. a -> HSPT xml m a
    Monad, Monad (HSPT xml m)
    Alternative (HSPT xml m)
    Alternative (HSPT xml m)
    -> Monad (HSPT xml m)
    -> (forall a. HSPT xml m a)
    -> (forall a. HSPT xml m a -> HSPT xml m a -> HSPT xml m a)
    -> MonadPlus (HSPT xml m)
    forall a. HSPT xml m a
    forall a. HSPT xml m a -> HSPT xml m a -> HSPT xml m a
    forall {xml} {m :: * -> *}. MonadPlus m => Monad (HSPT xml m)
    forall {xml} {m :: * -> *}. MonadPlus m => Alternative (HSPT xml m)
    forall xml (m :: * -> *) a. MonadPlus m => HSPT xml m a
    forall xml (m :: * -> *) a.
    MonadPlus m =>
    HSPT xml m a -> HSPT xml m a -> HSPT xml m a
    forall (m :: * -> *).
    Alternative m
    -> Monad m
    -> (forall a. m a)
    -> (forall a. m a -> m a -> m a)
    -> MonadPlus m
    $cmzero :: forall xml (m :: * -> *) a. MonadPlus m => HSPT xml m a
    mzero :: forall a. HSPT xml m a
    $cmplus :: forall xml (m :: * -> *) a.
    MonadPlus m =>
    HSPT xml m a -> HSPT xml m a -> HSPT xml m a
    mplus :: forall a. HSPT xml m a -> HSPT xml m a -> HSPT xml m a
    MonadPlus, Monad (HSPT xml m)
    Monad (HSPT xml m)
    -> (forall a. IO a -> HSPT xml m a) -> MonadIO (HSPT xml m)
    forall a. IO a -> HSPT xml m a
    forall {xml} {m :: * -> *}. MonadIO m => Monad (HSPT xml m)
    forall xml (m :: * -> *) a. MonadIO m => IO a -> HSPT xml m a
    forall (m :: * -> *).
    Monad m -> (forall a. IO a -> m a) -> MonadIO m
    $cliftIO :: forall xml (m :: * -> *) a. MonadIO m => IO a -> HSPT xml m a
    liftIO :: forall a. IO a -> HSPT xml m a
    MonadIO, MonadReader r, MonadWriter w, MonadState s, Monad (HSPT xml m)
    Monad (HSPT xml m)
    -> (forall a b.
        ((a -> HSPT xml m b) -> HSPT xml m a) -> HSPT xml m a)
    -> MonadCont (HSPT xml m)
    forall a b. ((a -> HSPT xml m b) -> HSPT xml m a) -> HSPT xml m a
    forall {xml} {m :: * -> *}. MonadCont m => Monad (HSPT xml m)
    forall xml (m :: * -> *) a b.
    MonadCont m =>
    ((a -> HSPT xml m b) -> HSPT xml m a) -> HSPT xml m a
    forall (m :: * -> *).
    Monad m -> (forall a b. ((a -> m b) -> m a) -> m a) -> MonadCont m
    $ccallCC :: forall xml (m :: * -> *) a b.
    MonadCont m =>
    ((a -> HSPT xml m b) -> HSPT xml m a) -> HSPT xml m a
    callCC :: forall a b. ((a -> HSPT xml m b) -> HSPT xml m a) -> HSPT xml m a
    MonadCont, MonadError e, Monad (HSPT xml m)
    Monad (HSPT xml m)
    -> (forall a. (a -> HSPT xml m a) -> HSPT xml m a)
    -> MonadFix (HSPT xml m)
    forall a. (a -> HSPT xml m a) -> HSPT xml m a
    forall {xml} {m :: * -> *}. MonadFix m => Monad (HSPT xml m)
    forall xml (m :: * -> *) a.
    MonadFix m =>
    (a -> HSPT xml m a) -> HSPT xml m a
    forall (m :: * -> *).
    Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
    $cmfix :: forall xml (m :: * -> *) a.
    MonadFix m =>
    (a -> HSPT xml m a) -> HSPT xml m a
    mfix :: forall a. (a -> HSPT xml m a) -> HSPT xml m a
    MonadFix)

    instance MonadTrans (HSPT xml) where
        lift :: forall (m :: * -> *) a. Monad m => m a -> HSPT xml m a
    lift = m a -> HSPT xml m a
    forall xml (m :: * -> *) a. m a -> HSPT xml m a
    HSPT

    instance (Functor m, Monad m) => (XMLGen (HSPT XML m)) where
        type    XMLType       (HSPT XML m) = XML
        type    StringType    (HSPT XML m) = Text
        newtype ChildType     (HSPT XML m) = HSPChild { forall (m :: * -> *). ChildType (HSPT XML m) -> XML
    unHSPChild :: XML }
        newtype AttributeType (HSPT XML m) = HSPAttr  { forall (m :: * -> *). AttributeType (HSPT XML m) -> Attribute
    unHSPAttr  :: Attribute }
        genElement :: Name (StringType (HSPT XML m))
    -> [XMLGenT (HSPT XML m) [AttributeType (HSPT XML m)]]
    -> [XMLGenT (HSPT XML m) [ChildType (HSPT XML m)]]
    -> XMLGenT (HSPT XML m) (XMLType (HSPT XML m))
    genElement Name (StringType (HSPT XML m))
    n [XMLGenT (HSPT XML m) [AttributeType (HSPT XML m)]]
    attrs [XMLGenT (HSPT XML m) [ChildType (HSPT XML m)]]
    childr          =
            do [Attribute]
    as <- ((AttributeType (HSPT XML m) -> Attribute)
    -> [AttributeType (HSPT XML m)] -> [Attribute]
    forall a b. (a -> b) -> [a] -> [b]
    map AttributeType (HSPT XML m) -> Attribute
    forall (m :: * -> *). AttributeType (HSPT XML m) -> Attribute
    unHSPAttr  ([AttributeType (HSPT XML m)] -> [Attribute])
    -> ([[AttributeType (HSPT XML m)]] -> [AttributeType (HSPT XML m)])
    -> [[AttributeType (HSPT XML m)]]
    -> [Attribute]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [[AttributeType (HSPT XML m)]] -> [AttributeType (HSPT XML m)]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat) ([[AttributeType (HSPT XML m)]] -> [Attribute])
    -> XMLGenT (HSPT XML m) [[AttributeType (HSPT XML m)]]
    -> XMLGenT (HSPT XML m) [Attribute]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [XMLGenT (HSPT XML m) [AttributeType (HSPT XML m)]]
    -> XMLGenT (HSPT XML m) [[AttributeType (HSPT XML m)]]
    forall (t :: * -> *) (m :: * -> *) a.
    (Traversable t, Monad m) =>
    t (m a) -> m (t a)
    forall (m :: * -> *) a. Monad m => [m a] -> m [a]
    sequence [XMLGenT (HSPT XML m) [AttributeType (HSPT XML m)]]
    attrs
               [XML]
    cs <- ((ChildType (HSPT XML m) -> XML)
    -> [ChildType (HSPT XML m)] -> [XML]
    forall a b. (a -> b) -> [a] -> [b]
    map ChildType (HSPT XML m) -> XML
    forall (m :: * -> *). ChildType (HSPT XML m) -> XML
    unHSPChild ([ChildType (HSPT XML m)] -> [XML])
    -> ([[ChildType (HSPT XML m)]] -> [ChildType (HSPT XML m)])
    -> [[ChildType (HSPT XML m)]]
    -> [XML]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [[ChildType (HSPT XML m)]] -> [ChildType (HSPT XML m)]
    forall (t :: * -> *) a. Foldable t => t [a] -> [a]
    concat) ([[ChildType (HSPT XML m)]] -> [XML])
    -> XMLGenT (HSPT XML m) [[ChildType (HSPT XML m)]]
    -> XMLGenT (HSPT XML m) [XML]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [XMLGenT (HSPT XML m) [ChildType (HSPT XML m)]]
    -> XMLGenT (HSPT XML m) [[ChildType (HSPT XML m)]]
    forall (t :: * -> *) (m :: * -> *) a.
    (Traversable t, Monad m) =>
    t (m a) -> m (t a)
    forall (m :: * -> *) a. Monad m => [m a] -> m [a]
    sequence [XMLGenT (HSPT XML m) [ChildType (HSPT XML m)]]
    childr
               XML -> XMLGenT (HSPT XML m) XML
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (NSName -> [Attribute] -> [XML] -> XML
    Element NSName
    Name (StringType (HSPT XML m))
    n [Attribute]
    as [XML]
    cs)
        xmlToChild :: XMLType (HSPT XML m) -> ChildType (HSPT XML m)
    xmlToChild                         = XML -> ChildType (HSPT XML m)
    XMLType (HSPT XML m) -> ChildType (HSPT XML m)
    forall (m :: * -> *). XML -> ChildType (HSPT XML m)
    HSPChild
        pcdataToChild :: StringType (HSPT XML m) -> ChildType (HSPT XML m)
    pcdataToChild StringType (HSPT XML m)
    str                  = XML -> ChildType (HSPT XML m)
    forall (m :: * -> *). XML -> ChildType (HSPT XML m)
    HSPChild (Text -> XML
    pcdata Text
    StringType (HSPT XML m)
    str)

    instance (Functor m, Monad m) => SetAttr (HSPT XML m) XML where
        setAll :: XML -> GenAttributeList (HSPT XML m) -> GenXML (HSPT XML m)
    setAll XML
    xml GenAttributeList (HSPT XML m)
    hats =
            do [AttributeType (HSPT XML m)]
    attrs <- GenAttributeList (HSPT XML m)
    hats
               case XML
    xml of
                 CDATA Bool
    _ Text
    _       -> XML -> XMLGenT (HSPT XML m) XML
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return XML
    xml
                 Element NSName
    n [Attribute]
    as [XML]
    cs -> XML -> XMLGenT (HSPT XML m) XML
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (XML -> XMLGenT (HSPT XML m) XML)
    -> XML -> XMLGenT (HSPT XML m) XML
    forall a b. (a -> b) -> a -> b
    $ NSName -> [Attribute] -> [XML] -> XML
    Element NSName
    n ((Attribute -> [Attribute] -> [Attribute])
    -> [Attribute] -> [Attribute] -> [Attribute]
    forall a b. (a -> b -> b) -> b -> [a] -> b
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr (:) [Attribute]
    as ((AttributeType (HSPT XML m) -> Attribute)
    -> [AttributeType (HSPT XML m)] -> [Attribute]
    forall a b. (a -> b) -> [a] -> [b]
    map AttributeType (HSPT XML m) -> Attribute
    forall (m :: * -> *). AttributeType (HSPT XML m) -> Attribute
    unHSPAttr [AttributeType (HSPT XML m)]
    attrs)) [XML]
    cs

    instance (Functor m, Monad m) => AppendChild (HSPT XML m) XML where
     appAll :: XML -> GenChildList (HSPT XML m) -> GenXML (HSPT XML m)
    appAll XML
    xml GenChildList (HSPT XML m)
    children =
            do [ChildType (HSPT XML m)]
    chs <- GenChildList (HSPT XML m)
    children
               case XML
    xml of
                 CDATA Bool
    _ Text
    _       -> XML -> XMLGenT (HSPT XML m) XML
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return XML
    xml
                 Element NSName
    n [Attribute]
    as [XML]
    cs -> XML -> XMLGenT (HSPT XML m) XML
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (XML -> XMLGenT (HSPT XML m) XML)
    -> XML -> XMLGenT (HSPT XML m) XML
    forall a b. (a -> b) -> a -> b
    $ NSName -> [Attribute] -> [XML] -> XML
    Element NSName
    n [Attribute]
    as ([XML]
    cs [XML] -> [XML] -> [XML]
    forall a. [a] -> [a] -> [a]
    ++ ((ChildType (HSPT XML m) -> XML)
    -> [ChildType (HSPT XML m)] -> [XML]
    forall a b. (a -> b) -> [a] -> [b]
    map ChildType (HSPT XML m) -> XML
    forall (m :: * -> *). ChildType (HSPT XML m) -> XML
    unHSPChild [ChildType (HSPT XML m)]
    chs))

    instance (Functor m, Monad m) => EmbedAsChild (HSPT XML m) XML where
        asChild :: XML -> GenChildList (HSPT XML m)
    asChild = [ChildType (HSPT XML m)] -> GenChildList (HSPT XML m)
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([ChildType (HSPT XML m)] -> GenChildList (HSPT XML m))
    -> (XML -> [ChildType (HSPT XML m)])
    -> XML
    -> GenChildList (HSPT XML m)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (ChildType (HSPT XML m)
    -> [ChildType (HSPT XML m)] -> [ChildType (HSPT XML m)]
    forall a. a -> [a] -> [a]
    :[]) (ChildType (HSPT XML m) -> [ChildType (HSPT XML m)])
    -> (XML -> ChildType (HSPT XML m))
    -> XML
    -> [ChildType (HSPT XML m)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XML -> ChildType (HSPT XML m)
    forall (m :: * -> *). XML -> ChildType (HSPT XML m)
    HSPChild

    instance (Functor m, Monad m) => EmbedAsChild (HSPT XML m) [XML] where
        asChild :: [XML] -> GenChildList (HSPT XML m)
    asChild = [ChildType (HSPT XML m)] -> GenChildList (HSPT XML m)
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([ChildType (HSPT XML m)] -> GenChildList (HSPT XML m))
    -> ([XML] -> [ChildType (HSPT XML m)])
    -> [XML]
    -> GenChildList (HSPT XML m)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (XML -> ChildType (HSPT XML m))
    -> [XML] -> [ChildType (HSPT XML m)]
    forall a b. (a -> b) -> [a] -> [b]
    map XML -> ChildType (HSPT XML m)
    forall (m :: * -> *). XML -> ChildType (HSPT XML m)
    HSPChild

    instance (Functor m, Monad m) => EmbedAsChild (HSPT XML m) String where
        asChild :: String -> GenChildList (HSPT XML m)
    asChild = [ChildType (HSPT XML m)] -> GenChildList (HSPT XML m)
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([ChildType (HSPT XML m)] -> GenChildList (HSPT XML m))
    -> (String -> [ChildType (HSPT XML m)])
    -> String
    -> GenChildList (HSPT XML m)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (ChildType (HSPT XML m)
    -> [ChildType (HSPT XML m)] -> [ChildType (HSPT XML m)]
    forall a. a -> [a] -> [a]
    :[]) (ChildType (HSPT XML m) -> [ChildType (HSPT XML m)])
    -> (String -> ChildType (HSPT XML m))
    -> String
    -> [ChildType (HSPT XML m)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XML -> ChildType (HSPT XML m)
    forall (m :: * -> *). XML -> ChildType (HSPT XML m)
    HSPChild (XML -> ChildType (HSPT XML m))
    -> (String -> XML) -> String -> ChildType (HSPT XML m)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> XML
    pcdata (Text -> XML) -> (String -> Text) -> String -> XML
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> Text
    Lazy.pack

    instance (Functor m, Monad m) => EmbedAsChild (HSPT XML m) Text where
        asChild :: Text -> GenChildList (HSPT XML m)
    asChild = [ChildType (HSPT XML m)] -> GenChildList (HSPT XML m)
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([ChildType (HSPT XML m)] -> GenChildList (HSPT XML m))
    -> (Text -> [ChildType (HSPT XML m)])
    -> Text
    -> GenChildList (HSPT XML m)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (ChildType (HSPT XML m)
    -> [ChildType (HSPT XML m)] -> [ChildType (HSPT XML m)]
    forall a. a -> [a] -> [a]
    :[]) (ChildType (HSPT XML m) -> [ChildType (HSPT XML m)])
    -> (Text -> ChildType (HSPT XML m))
    -> Text
    -> [ChildType (HSPT XML m)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XML -> ChildType (HSPT XML m)
    forall (m :: * -> *). XML -> ChildType (HSPT XML m)
    HSPChild (XML -> ChildType (HSPT XML m))
    -> (Text -> XML) -> Text -> ChildType (HSPT XML m)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> XML
    pcdata

    instance (Functor m, Monad m) => EmbedAsChild (HSPT XML m) Strict.Text where
        asChild :: Text -> GenChildList (HSPT XML m)
    asChild = [ChildType (HSPT XML m)] -> GenChildList (HSPT XML m)
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([ChildType (HSPT XML m)] -> GenChildList (HSPT XML m))
    -> (Text -> [ChildType (HSPT XML m)])
    -> Text
    -> GenChildList (HSPT XML m)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (ChildType (HSPT XML m)
    -> [ChildType (HSPT XML m)] -> [ChildType (HSPT XML m)]
    forall a. a -> [a] -> [a]
    :[]) (ChildType (HSPT XML m) -> [ChildType (HSPT XML m)])
    -> (Text -> ChildType (HSPT XML m))
    -> Text
    -> [ChildType (HSPT XML m)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XML -> ChildType (HSPT XML m)
    forall (m :: * -> *). XML -> ChildType (HSPT XML m)
    HSPChild (XML -> ChildType (HSPT XML m))
    -> (Text -> XML) -> Text -> ChildType (HSPT XML m)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> XML
    pcdata (Text -> XML) -> (Text -> Text) -> Text -> XML
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    Lazy.fromStrict

    instance (Functor m, Monad m) => EmbedAsChild (HSPT XML m) Char where
        asChild :: Char -> GenChildList (HSPT XML m)
    asChild = [ChildType (HSPT XML m)] -> GenChildList (HSPT XML m)
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([ChildType (HSPT XML m)] -> GenChildList (HSPT XML m))
    -> (Char -> [ChildType (HSPT XML m)])
    -> Char
    -> GenChildList (HSPT XML m)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (ChildType (HSPT XML m)
    -> [ChildType (HSPT XML m)] -> [ChildType (HSPT XML m)]
    forall a. a -> [a] -> [a]
    :[]) (ChildType (HSPT XML m) -> [ChildType (HSPT XML m)])
    -> (Char -> ChildType (HSPT XML m))
    -> Char
    -> [ChildType (HSPT XML m)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> ChildType (HSPT XML m)
    StringType (HSPT XML m) -> ChildType (HSPT XML m)
    forall (m :: * -> *). XMLGen m => StringType m -> ChildType m
    pcdataToChild (Text -> ChildType (HSPT XML m))
    -> (Char -> Text) -> Char -> ChildType (HSPT XML m)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Char -> Text
    Lazy.singleton

    instance (Functor m, Monad m) => EmbedAsChild (HSPT XML m) () where
        asChild :: () -> GenChildList (HSPT XML m)
    asChild = [ChildType (HSPT XML m)] -> GenChildList (HSPT XML m)
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([ChildType (HSPT XML m)] -> GenChildList (HSPT XML m))
    -> (() -> [ChildType (HSPT XML m)])
    -> ()
    -> GenChildList (HSPT XML m)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . [ChildType (HSPT XML m)] -> () -> [ChildType (HSPT XML m)]
    forall a b. a -> b -> a
    const []

    instance (Monad m, Functor m) => EmbedAsAttr (HSPT XML m) Attribute where
        asAttr :: Attribute -> GenAttributeList (HSPT XML m)
    asAttr = [AttributeType (HSPT XML m)] -> GenAttributeList (HSPT XML m)
    forall a. a -> XMLGenT (HSPT XML m) a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([AttributeType (HSPT XML m)] -> GenAttributeList (HSPT XML m))
    -> (Attribute -> [AttributeType (HSPT XML m)])
    -> Attribute
    -> GenAttributeList (HSPT XML m)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (AttributeType (HSPT XML m)
    -> [AttributeType (HSPT XML m)] -> [AttributeType (HSPT XML m)]
    forall a. a -> [a] -> [a]
    :[]) (AttributeType (HSPT XML m) -> [AttributeType (HSPT XML m)])
    -> (Attribute -> AttributeType (HSPT XML m))
    -> Attribute
    -> [AttributeType (HSPT XML m)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Attribute -> AttributeType (HSPT XML m)
    forall (m :: * -> *). Attribute -> AttributeType (HSPT XML m)
    HSPAttr

    instance (Functor m, Monad m) => EmbedAsAttr (HSPT XML m) (Attr Text Text) where
        asAttr :: Attr Text Text -> GenAttributeList (HSPT XML m)
    asAttr (Text
    n := Text
    v) = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, (Text -> AttrValue
    pAttrVal Text
    v))

    instance (Functor m, Monad m) => EmbedAsAttr (HSPT XML m) (Attr Strict.Text Text) where
        asAttr :: Attr Text Text -> GenAttributeList (HSPT XML m)
    asAttr (Text
    n := Text
    v) = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, (Text -> AttrValue
    pAttrVal Text
    v))

    instance (Functor m, Monad m) => EmbedAsAttr (HSPT XML m) (Attr Strict.Text Strict.Text) where
        asAttr :: Attr Text Text -> GenAttributeList (HSPT XML m)
    asAttr (Text
    n := Text
    v) = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, (Text -> AttrValue
    pAttrVal (Text -> AttrValue) -> Text -> AttrValue
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    Lazy.fromStrict Text
    v))

    instance (Functor m, Monad m) => EmbedAsAttr (HSPT XML m) (Attr Text Strict.Text) where
        asAttr :: Attr Text Text -> GenAttributeList (HSPT XML m)
    asAttr (Text
    n := Text
    v) = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, (Text -> AttrValue
    pAttrVal (Text -> AttrValue) -> Text -> AttrValue
    forall a b. (a -> b) -> a -> b
    $ Text -> Text
    Lazy.fromStrict Text
    v))

    instance (Monad m, Functor m) => EmbedAsAttr (HSPT XML m) (Attr Text Char) where
        asAttr :: Attr Text Char -> GenAttributeList (HSPT XML m)
    asAttr (Text
    n := Char
    c)  = Attr Text Text -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Text
    n Text -> Text -> Attr Text Text
    forall n a. n -> a -> Attr n a
    := Char -> Text
    Lazy.singleton Char
    c)

    instance (Monad m, Functor m) => EmbedAsAttr (HSPT XML m) (Attr Strict.Text Char) where
        asAttr :: Attr Text Char -> GenAttributeList (HSPT XML m)
    asAttr (Text
    n := Char
    c)  = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, Text -> AttrValue
    pAttrVal (Text -> AttrValue) -> Text -> AttrValue
    forall a b. (a -> b) -> a -> b
    $ Char -> Text
    Lazy.singleton Char
    c)

    instance (Functor m, Monad m) => EmbedAsAttr (HSPT XML m) (Attr Text Bool) where
        asAttr :: Attr Text Bool -> GenAttributeList (HSPT XML m)
    asAttr (Text
    n := Bool
    True)  = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, Text -> AttrValue
    pAttrVal (Text -> AttrValue) -> Text -> AttrValue
    forall a b. (a -> b) -> a -> b
    $ String -> Text
    forall a. IsString a => String -> a
    fromString String
    "true")
        asAttr (Text
    n := Bool
    False) = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, Text -> AttrValue
    pAttrVal (Text -> AttrValue) -> Text -> AttrValue
    forall a b. (a -> b) -> a -> b
    $ String -> Text
    forall a. IsString a => String -> a
    fromString String
    "false")

    instance (Functor m, Monad m) => EmbedAsAttr (HSPT XML m) (Attr Strict.Text Bool) where
        asAttr :: Attr Text Bool -> GenAttributeList (HSPT XML m)
    asAttr (Text
    n := Bool
    True)  = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, Text -> AttrValue
    pAttrVal (Text -> AttrValue) -> Text -> AttrValue
    forall a b. (a -> b) -> a -> b
    $ String -> Text
    forall a. IsString a => String -> a
    fromString String
    "true")
        asAttr (Text
    n := Bool
    False) = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, Text -> AttrValue
    pAttrVal (Text -> AttrValue) -> Text -> AttrValue
    forall a b. (a -> b) -> a -> b
    $ String -> Text
    forall a. IsString a => String -> a
    fromString String
    "false")

    instance (Functor m, Monad m) => EmbedAsAttr (HSPT XML m) (Attr Text Int) where
        asAttr :: Attr Text Int -> GenAttributeList (HSPT XML m)
    asAttr (Text
    n := Int
    i)  = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, Text -> AttrValue
    pAttrVal (Text -> AttrValue) -> Text -> AttrValue
    forall a b. (a -> b) -> a -> b
    $ String -> Text
    forall a. IsString a => String -> a
    fromString (Int -> String
    forall a. Show a => a -> String
    show Int
    i))

    instance (Functor m, Monad m) => EmbedAsAttr (HSPT XML m) (Attr Strict.Text Int) where
        asAttr :: Attr Text Int -> GenAttributeList (HSPT XML m)
    asAttr (Text
    n := Int
    i)  = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, Text -> AttrValue
    pAttrVal (Text -> AttrValue) -> Text -> AttrValue
    forall a b. (a -> b) -> a -> b
    $ String -> Text
    forall a. IsString a => String -> a
    fromString (Int -> String
    forall a. Show a => a -> String
    show Int
    i))

    instance (Functor m, Monad m) => EmbedAsAttr (HSPT XML m) (Attr Text ()) where
        asAttr :: Attr Text () -> GenAttributeList (HSPT XML m)
    asAttr (Text
    n := ())  = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, AttrValue
    NoValue)

    instance (Functor m, Monad m) => EmbedAsAttr (HSPT XML m) (Attr Strict.Text ()) where
        asAttr :: Attr Text () -> GenAttributeList (HSPT XML m)
    asAttr (Text
    n := ())  = Attribute -> GenAttributeList (HSPT XML m)
    forall (m :: * -> *) a. EmbedAsAttr m a => a -> GenAttributeList m
    asAttr (Attribute -> GenAttributeList (HSPT XML m))
    -> Attribute -> GenAttributeList (HSPT XML m)
    forall a b. (a -> b) -> a -> b
    $ (NSName, AttrValue) -> Attribute
    MkAttr (Text -> NSName
    forall n s. IsName n s => n -> Name s
    toName Text
    n, AttrValue
    NoValue)

    instance (Functor m, Monad m) => XMLGenerator (HSPT XML m)