Module RW.Base

This library defines the class ReadWrite which is the basis to define compact data representations for various types. Furthermore, instances of this class are defined for various standard types defined in the prelude.

Author
Lasse Züngel
Version
August 2025

Exported Datatypes


data RWParameters

Writing RWParameters .

Constructors:

  • RWParameters :: Int -> Int -> RWParameters

    Fields:

    • minStrLen :: Int
    • alphabetLen :: Int

data RWType

Represents a type in the compact data representation.

Constructors:

Known instances:


Exported Functions


defaultParams :: RWParameters  Deterministic 

Default RWParameters for writing compact data.

Further infos:
  • solution complete, i.e., able to compute all solutions

monoRWType :: String -> RWType  Deterministic 

Creates a representation of a monomorphic type.

Further infos:
  • solution complete, i.e., able to compute all solutions

readData :: ReadWrite a => String -> Maybe a  Deterministic 

Data reading and writing Parses a compact data representation and returns the value. If the parse failes (e.g. due to a type mismatch), Nothing is returned.

This operation might fail if the input is not well-formed.


readDataFile :: ReadWrite a => String -> IO (Maybe a)  Deterministic 

Reads a file containing a compact data representation, parses the contents and returns the value.

If the parse failes (e.g. due to a type mismatch or a bad input format), Nothing is returned.


writeDataFile :: ReadWrite a => String -> a -> IO ()  Deterministic 

Writes some data to a file containing a compact data representation.


writeDataFileP :: ReadWrite a => RWParameters -> String -> a -> IO ()  Deterministic 

Writes some data to a file containing a compact data representation and use specific RWParameters .


showData :: ReadWrite a => a -> String  Deterministic 

Converts a given data value into a compact string representation.

This is rarely what you want. Use writeDataFile if you want to write the data into a file.


showDataP :: ReadWrite a => RWParameters -> a -> String  Deterministic 

Converts data to a compact string representation using specific RWParameters .

This is rarely what you want. Use writeDataFileP if you want to write the data into a file.


Exported Classes


class ReadWrite a

The class ReadWrite contains the interface to be implemented by compact readers and writers of data.

Methods:

readRW :: Trie String -> String -> (a, String)  

showRW :: RWParameters -> Trie String -> a -> (Trie String, ShowS)  

writeRW :: RWParameters -> Handle -> a -> Trie String -> IO (Trie String)  

typeOf :: a -> RWType  

Returns the type of the value.

readListRW :: Trie String -> String -> ([a], String)  

showListRW :: RWParameters -> Trie String -> [a] -> (Trie String, ShowS)  

writeListRW :: RWParameters -> Handle -> [a] -> Trie String -> IO (Trie String)