packages feed

RefSerialize 0.2.1 → 0.2.2

raw patch · 3 files changed

+24/−36 lines, 3 files

Files

Data/Serialize.hs view
@@ -1,6 +1,5 @@ {-# OPTIONS -fglasgow-exts -fallow-undecidable-instances -fallow-overlapping-instances  #-} module Data.Serialize where-import GHC.Prim import GHC.Exts import Unsafe.Coerce import Data.List(isPrefixOf,insertBy,elem)
RefSerialize.cabal view
@@ -1,5 +1,5 @@ name:                RefSerialize-version:             0.2.1+version:             0.2.2 synopsis:            Write to and read from Strings maintaining internal memory references  description:                               Read, Show and Data.Binary do not check for pointers to the same address @@ -12,13 +12,13 @@                      This package allows the serialization and deserialization of large data structures without duplication of data, with                      the result of optimized performance and memory usage. It is also useful for debugging purposes.                      -                     There are automatic derived instances for instances of Read/Show, lists and strings. the deserializer-                     contains a subset of Parsec.Token for deserialization. +                     There are automatic derived instances for instances of Read/Show. Lists of non-chars have its own instance.+                     The deserializer contains a subset of Parsec.Token for defining deserializing parsers.                                             Every instance of Show/Read is also a instance of Data.RefSerialize                                            the serialized string has the form "expr( var1, ...varn) where  var1=value1,..valn=valueN " so that the-                     string can ve EVALuated.+                     string can ve EVALuated. So the entire deserialization can be substituted by eval.                                            See demo.hs and tutorial. I presumably will add a entry in haskell-web.blogspot.com                      @@ -36,5 +36,5 @@ build-Depends:       base,containers Cabal-Version:       >= 1.2 -exposed-modules:     Data.RefSerialize+exposed-modules:     Data.RefSerialize, Data.Parser ghc-options:         
tutorial.txt view
@@ -1,49 +1,42 @@-GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help-Loading package base ... linking ... done.-Prelude>:l Data.RefSerialize- Ok, modules loaded: Data.RefSerialize, Data.Parser, Data.Serialize.-Loading package array-0.1.0.0 ... linking ... done.-Loading package containers-0.1.0.1 ... linking ... done.- runW applies showp, the serialization parser of the instance Int for the RefSerialize class  Data.RefSerialize>let x= 5 :: Int Data.RefSerialize>runW $ showp x-Data.RefSerialize>"5"+"5"  every instance of Read and Show is an instance of RefSerialize. for how to construct showp and readp parsers, see the demo.hs  rshowp is derived from showp, it labels the serialized data with a variable name  Data.RefSerialize>runW $ rshowp x-Data.RefSerialize> " v8 where {v8= 5; }"+" v8 where {v8= 5; }"  Data.RefSerialize>runW $ rshowp [2::Int,3::Int]-Data.RefSerialize> " v6 where {v6= [ v9,  v10]; v9= 2; v10= 3; }"+" v6 where {v6= [ v9,  v10]; v9= 2; v10= 3; }"  while showp does a normal show serialization  Data.RefSerialize>runW $ showp [x,x]-Data.RefSerialize> "[5, 5]"+"[5, 5]"  rshowp variables are serialized memory references: no piece of data that point to the same addrees is serialized but one time  Data.RefSerialize>runW $ rshowp [x,x]-Data.RefSerialize> " v9 where {v6= 5; v9= [ v6, v6]; }"+" v9 where {v6= 5; v9= [ v6, v6]; }"  "this happens recursively" -let xs= [x,x] in str = runW $ rshowp [xs,xs]-str+Data.RefSerialize>let xs= [x,x] in str = runW $ rshowp [xs,xs]+Data.RefSerialize>str " v8 where {v8= [ v10, v10]; v9= 5; v10= [ v9, v9]; }" -the rshowp serialized data is read with rreadp. the showp serialized data is read by readp+the rshowp serialized data is read with rreadp. The showp serialized data is read by readp  Data.RefSerialize>let xss= runR rreadp str :: [[Int]] Data.RefSerialize>print xss [[5,5],[5,5]] -echo "this is the deserialized data"+this is the deserialized data  the deserialized data keep the references!! pointers are restored! That is the whole point! @@ -63,33 +56,29 @@  by default the referencing parser is constructed by: -   rshowp= insertVar showp+rshowp= insertVar showp    rreadp= readVar readp but this can be redefined. See for example the instance of [] in RefSerialize.hs  This is an example of a showp parser for a simple data structure. -data S= S Int Int deriving ( Show, Eq)       +data S= S Int Int deriving ( Show, Eq)        instance  Serialize S  where     showp (S x y)= do                     xs <- rshowp x  -- rshowp parsers can be inside showp parser                     ys <- rshowp y                     return $ "S "++xs++" "++ys-       -       -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; }     +      +      +     readp =  do                     symbol "S"     -- I included a (almost) complete Parsec for deserialization-                    x <- rreadp    +                    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; }