-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Write to and read from ByteStrings maintaining internal memory references -- -- Read, Show and Binary instances do not check for internal data -- references to the same address. As a result, the data is duplicated -- when serialized. This is a waste of space in the filesystem and also a -- waste of serialization time. but the worst consequence is that, when -- the serialized data is read, it allocates multiple copies for the same -- object when referenced multiple times. Because multiple referenced -- data is very typical in a pure language such is Haskell, this means -- that the resulting data loose the beatiful economy of space and -- processing time that referential transparency permits. -- -- See Data.RefSerialize for details @package RefSerialize @version 0.3.0.0 module Data.RefSerialize.Serialize type MFun = Char type VarName = String data ShowF Expr :: ByteString -> ShowF Var :: Int -> ShowF type Context = HashTable Int (StableName MFun, MFun, [ShowF], Int) data Error Error :: String -> Error data StatW StatW :: (Context, [ShowF], ByteString) -> StatW data STW a STW :: (StatW -> (StatW, a)) -> STW a empty :: IO (HashTable Int val) assocs :: Ord a => HashTable a b -> [(a, b)] insert :: key -> val -> HashTable key val -> HashTable key val delete :: key -> HashTable key val -> HashTable key val lookup :: key -> HashTable key val -> Maybe val toList :: HashTable key val -> [(key, val)] fromList :: [(Int, val)] -> HashTable Int val readContext :: ByteString -> ByteString -> (ByteString, ByteString) hasht :: a -> (Int, t) varName :: a -> [Char] numVar :: String -> Maybe Int instance [overlap ok] Show ShowF instance [overlap ok] Monad STW -- | A Parsec parser for the refSerialize monad. See package Parsec. all -- the functions have the same meaning module Data.RefSerialize.Parser data STR a STR :: (StatR -> Either Error (StatR, a)) -> STR a data StatR StatR :: (Context, ByteString, ByteString) -> StatR () :: STR a -> String -> STR a (<|>) :: STR a -> STR a -> STR a char :: Char -> STR Char anyChar :: STR Char string :: [Char] -> STR [Char] upper :: STR Char space :: STR Char digit :: STR Char sepBy :: STR a -> STR sep -> STR [a] between :: Monad m => m a -> m a1 -> m b -> m b choice :: [STR a] -> STR a option :: a -> STR a -> STR a notFollowedBy :: Show t => STR t -> STR () many :: STR a -> STR [a] manyTill :: STR a1 -> STR a -> STR [a1] oneOf :: [Char] -> STR Char noneOf :: [Char] -> STR Char bool :: STR Bool try :: STR b -> STR b empty :: STR () readContent :: STR ByteString charLiteral :: STR Char stringLiteral :: STR [Char] natural :: STR Integer integer :: STR Integer float :: STR Double naturalOrFloat :: STR (Either Integer Double) decimal :: STR Integer hexadecimal :: STR Integer octal :: STR Integer symbol :: [Char] -> STR [Char] lexeme :: STR b -> STR b whiteSpace :: STR () parens :: STR a -> STR a braces :: STR a -> STR a angles :: STR a -> STR a brackets :: STR a -> STR a semi :: STR [Char] comma :: STR [Char] colon :: STR [Char] dot :: STR [Char] semiSep :: STR a -> STR [a] semiSep1 :: STR a -> STR [a] commaSep :: STR a -> STR [a] commaSep1 :: STR a -> STR [a] instance MonadPlus STR instance Monad STR -- | Read, Show and Data.Binary do not check for repeated references to the -- same address. As a result, the data is duplicated when serialized. -- This is a waste of space in the filesystem and also a waste of -- serialization time. but the worst consequence is that, when the -- serialized data is read, it allocates multiple copies for the same -- object when referenced multiple times. Because multiple referenced -- data is very typical in a pure language such is Haskell, this means -- that the resulting data loose the beatiful economy of space and -- processing time that referential transparency permits. -- -- This package leverages Show, Read and Data.Binary instances while it -- permits textual as well as binary serialization keeping internal -- references. -- -- NOTE: to avoid long lists of variables with only one reference, now -- variables not referenced two or more times are inlined so rshowp -- serializes the same result than showp in these cases. However, showp -- is faster. In correspondence, rreadp call readp when there is no -- variable serialized. -- -- This is an example of a showp parser for a simple data structure. -- --
--   data S= S Int Int deriving ( Show, Eq)
--   
--   instance  Serialize S  where
--      showp (S x y)= do
--                      insertString "S"
--                      rshowp x       -- rshowp parsers can be inside showp parser
--                      rshowp y
--   
--   
--      readp =  do
--                      symbol "S"     -- I included a (almost) complete Parsec for deserialization
--                      x <- rreadp
--                      y <- rreadp
--                      return $ S x y
--   
-- -- there is a mix between referencing and no referencing parser here: -- --
--   Data.RefSerialize>putStrLn $ runW $ showp $ S x x
--   S  v23 v23 where {v23= 5; }
--   
module Data.RefSerialize class Serialize c showp :: Serialize c => c -> STW () readp :: Serialize c => STR c -- | insert a reference (a variable in the where section). rshowp :: Serialize c => c -> STW () rreadp :: Serialize c => STR c -- | return the serialization instead of updating the writer showps :: Serialize a => a -> STW ByteString -- | return the variable name of the serialized data, which is put in the -- context and does not update the writer rshowps :: Serialize c => c -> STW ByteString -- | deserialize the string with the parser runR :: STR a -> ByteString -> a -- | serialize x with the parser runW :: STW () -> ByteString -- | if a is an instance of Show, showpText can be used as the showp method -- the drawback is that the data inside is not inspected for common -- references so it is recommended to create your own readp method for -- your complex data structures showpText :: Show a => a -> STW () -- | if a is an instance of Read, readpText can be used as the readp method -- the drawback is that the data inside is not inspected for common -- references so it is recommended to create your own readp method for -- your complex data structures readpText :: Read a => STR a -- | serialize a variable which has a Binary instance showpBinary :: Binary a => a -> STW () -- | deserialize a variable serialized by showpBinary readpBinary :: Binary a => STR a -- | Write a String in the serialized output with an added whitespace. -- Deserializable with symbol insertString :: ByteString -> STW () -- | Write a char in the serialized output (no spaces) insertChar :: Char -> STW () -- | use the rshowp parser to serialize the object rShow c= runW $ -- rshowp c rShow :: Serialize c => c -> ByteString -- | deserialize trough the rreadp parser rRead str= runR rreadp $ -- str rRead :: Serialize c => ByteString -> c -- | insert a variable at this position. The expression value is inserted -- in the where section if it is not already created. If the -- address of this object being parsed correspond with an address already -- parsed and it is in the where section, then the same variable name is -- used runW showp (1::Int) -> 1 runW (insertVar showp) -- (1::Int) -> v1 where { v1=1} runW (insertVar showp) [(1::Int) ,1] -- -> [v1.v1] where { v1=1} This is useful when the object is -- referenced many times insertVar :: (a -> STW ()) -> a -> STW () -- | deserialize a variable serialized with insertVar. Memory references -- are restored readVar :: Serialize c => STR c -> STR c varName :: a -> [Char] takep :: Int -> STR ByteString readHexp :: (Num a, Integral a) => STR a showHexp :: (Num a, Integral a, Show a) => a -> STW () type Context = HashTable Int (StableName MFun, MFun, [ShowF], Int) -- | return the serialized list of variable values useful for delayed -- deserialzation of expresions, in case of dynamic variables were -- deserialization is done when needed, once the type is known with -- runRC getRContext :: STR (Context, ByteString) getWContext :: STW (Context, ByteString) newContext :: IO Context -- | serialize the variables. if the Bool flag is true, it prepend the text -- with the string where showContext :: Context -> Bool -> ByteString -- | read an expression with the variables definedd in a context passed as -- parameter. runRC :: (Context, ByteString) -> STR a -> ByteString -> a -- | serialize x witn a given context and the parser runWC :: (Context, ByteString) -> STW () -> ByteString instance [overlap ok] (Show a, Read a) => Serialize a instance [overlap ok] (Serialize a, Serialize b) => Serialize (Either a b) instance [overlap ok] Serialize a => Serialize (Maybe a) instance [overlap ok] (Serialize a, Ord a, Serialize b) => Serialize (Map a b) instance [overlap ok] (Serialize a, Serialize b, Serialize c, Serialize d) => Serialize (a, b, c, d) instance [overlap ok] (Serialize a, Serialize b, Serialize c) => Serialize (a, b, c) instance [overlap ok] (Serialize a, Serialize b) => Serialize (a, b) instance [overlap ok] Serialize a => Serialize [a] instance [overlap ok] Serialize String