-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | HSX (Haskell Source with XML) allows literal XML syntax to be used in Haskell source code. -- -- HSX (Haskell Source with XML) allows literal XML syntax to be used in -- Haskell source code. The trhsx preprocessor translates .hsx source -- files into ordinary .hs files. Literal XML syntax is translated into -- function calls for creating XML values of the appropriate forms. trhsx -- transforms literal XML syntax into a series of function calls. Any -- project can make use of the syntax by providing definitions for those -- functions, and the XML values produced will be of the types specified. -- This works for any types, since trhsx doesn't make any assumptions, or -- inserts any information depending on types. XMLGenerator defines a few -- typeclasses that together cover the functions injected by the -- preprocessor. A project that uses these classes to provide the -- semantics for the injected syntax will be able to use any functions -- written in terms of these, allowing better code reusability than if -- each project defines its own semantics for the XML syntax. Also, the -- classes makes it possible to use the literal syntax at different types -- within the same module. Achieving that is not as simple as it may -- seem, but the XMLGenerator module provides all the necessary -- machinery. @package hsx @version 0.4 -- | The class and monad transformer that forms the basis of the literal -- XML syntax translation. Literal tags will be translated into functions -- of the GenerateXML class, and any instantiating monads with associated -- XML types can benefit from that syntax. module HSX.XMLGenerator -- | The monad transformer that allows a monad to generate XML values. newtype XMLGenT m a XMLGenT :: (m a) -> XMLGenT m a -- | un-lift. unXMLGenT :: XMLGenT m a -> m a type Name = (Maybe String, String) -- | Generate XML values in some XMLGenerator monad. class (Monad m) => XMLGenerator m where { type family XML m; type family Child m; type family Attribute m; { genEElement n ats = genElement n ats [] } } genElement :: (XMLGenerator m) => Name -> [XMLGenT m (Attribute m)] -> [XMLGenT m [Child m]] -> XMLGenT m (XML m) genEElement :: (XMLGenerator m) => Name -> [XMLGenT m (Attribute m)] -> XMLGenT m (XML m) -- | Embed values as child nodes of an XML element. The parent type will be -- clear from the context so it is not mentioned. class EmbedAsChild a c asChild :: (EmbedAsChild a c) => a -> c -- | Similarly embed values as attributes of an XML element. class EmbedAsAttr a at asAttr :: (EmbedAsAttr a at) => a -> at data Attr n a (:=) :: n -> a -> Attr n a -- | Set attributes on XML elements class (XMLGenerator m) => SetAttr m t setAttr :: (SetAttr m t) => t -> XMLGenT m (Attribute m) -> XMLGenT m (XML m) setAll :: (SetAttr m t) => t -> XMLGenT m [Attribute m] -> XMLGenT m (XML m) set :: (SetAttr m t, EmbedAsAttr a (XMLGenT m (Attribute m))) => t -> a -> XMLGenT m (XML m) (<@) :: (SetAttr m t, EmbedAsAttr a (XMLGenT m (Attribute m))) => t -> a -> XMLGenT m (XML m) (<<@) :: (SetAttr m t, EmbedAsAttr a (XMLGenT m (Attribute m))) => t -> [a] -> XMLGenT m (XML m) class (XMLGenerator m) => AppendChild m t appChild :: (AppendChild m t) => t -> XMLGenT m (Child m) -> XMLGenT m (XML m) appAll :: (AppendChild m t) => t -> XMLGenT m [Child m] -> XMLGenT m (XML m) app :: (AppendChild m t, EmbedAsChild c (XMLGenT m [Child m])) => t -> c -> XMLGenT m (XML m) (<:) :: (AppendChild m t, EmbedAsChild c (XMLGenT m [Child m])) => t -> c -> XMLGenT m (XML m) -- | Names can be simple or qualified with a domain. We want to -- conveniently use both simple strings or pairs wherever a Name is -- expected. class (Show n) => IsName n toName :: (IsName n) => n -> Name class TypeCast a b | a -> b, b -> a typeCast :: (TypeCast a b) => a -> b class TypeCast' t a b | t a -> b, t b -> a typeCast' :: (TypeCast' t a b) => t -> a -> b class TypeCast'' t a b | t a -> b, t b -> a typeCast'' :: (TypeCast'' t a b) => t -> a -> b instance [overlap ok] (Show n, Show a) => Show (Attr n a) instance [overlap ok] (Monad m) => Monad (XMLGenT m) instance [overlap ok] (Functor m) => Functor (XMLGenT m) instance [overlap ok] (MonadIO m) => MonadIO (XMLGenT m) instance [overlap ok] TypeCast'' () a a instance [overlap ok] (TypeCast'' t a b) => TypeCast' t a b instance [overlap ok] (TypeCast' () a b) => TypeCast a b instance [overlap ok] IsName (String, String) instance [overlap ok] IsName String instance [overlap ok] IsName Name instance [overlap ok] MonadTrans XMLGenT