hexpat-pickle-generic-0.1.1: Picklers for de/serialising Generic data types to and from XML

Safe HaskellNone

Text.XML.Expat.Pickle.Generic

Contents

Synopsis

Class

class IsXML a whereSource

Instances

Functions

Re-exported Data Types

data PU t a

A two-way pickler/unpickler that pickles an arbitrary data type ''a'' to a part of an XML tree ''t''. A PU can be composed using the pickler primitives defined in this module.

unpickleTree, unpickleTree' and pickleTree should be used directly by the caller.

Constructors

PU 

Fields

unpickleTree :: t -> a

Lazily convert a t XML tree part into a Haskell value of type a. In the event of an error, it throws UnpickleException.

unpickleTree' :: t -> Either String a

strictly convert a t XML tree part into a Haskell value of type a, or give an unpickling error message as Left error.

pickleTree :: a -> t

Convert a Haskell value of type a to a t XML tree part.

Options

data GenericXMLOptions Source

Constructors

GenericXMLOptions 

Fields

constructorTagModifier :: String -> String

Function applied to constructor tags.

fieldLabelModifier :: String -> String

Function applied to record field labels.

Generics

genericXMLPickler :: (Generic x, GIsXML t (Rep x)) => Options -> PU t xSource

Combinators

xpSum :: PU t (f r) -> PU t (g r) -> PU t ((f :+: g) r)Source

xpEither :: PU t a -> PU t b -> PU t (Either a b)Source

Re-exported Combinators

xpText0 :: PU text text

Convert XML text content <-> String. Handles empty strings.

xpText :: GenericXMLString text => PU text text

Convert XML text content <-> String. Empty strings result in unpickle failure (Be warned!).

xpList0 :: Show tag => PU [Node tag text] a -> PU [Node tag text] [a]

Convert XML text <-> a list of elements. Unlike xpList, this function uses no more elements as the end of list condition, which means it can evaluate its children lazily.

Any error in a child will cause an error to be reported.

xpList :: Show tag => PU [Node tag text] a -> PU [Node tag text] [a]

Convert XML text <-> a list of elements. During unpickling, failure of the argument unpickler is the end-of-list condition (and it isn't a failure).

Note on lazy unpickle: Because we're using a failure to pickle a child as the end condition it means we're only lazy at the top-level xpList. Children of xpList are evaluated strictly. Use xpList0 to fix this.

xpContent :: GenericXMLString text => PU text a -> PU [Node tag text] a

If you have a pickler that works with text, and you want to use it as text content of an XML element, you need to wrap it with xpContent. See the example at the top.

xpPrim :: (Read b, Show b, GenericXMLString t) => PU [Node a t] bSource

xpWrap :: (a -> b, b -> a) -> PU t a -> PU t b

Apply a lens to convert the type of your data structure to/from types that the pickler primitives can handle, with the unpickle case first. Mostly this means the tuples used by xpPair and friends. A typical example is:

 xpWrap (\(name, address) -> Person name address,
         \(Person name address) -> (name, address)) $ ...