Module ReadShowTerm

Library for converting ground terms to strings and vice versa.

Author: Michael Hanus

Version: April 2005

Summary of exported operations:

showTerm :: a -> String   
Transforms a ground(!) term into a string representation in standard prefix notation.
showQTerm :: a -> String   
Transforms a ground(!) term into a string representation in standard prefix notation.
readsUnqualifiedTerm :: [String] -> String -> [(a,String)]   
Transform a string containing a term in standard prefix notation without module qualifiers into the corresponding data term.
readUnqualifiedTerm :: [String] -> String -> a   
Transforms a string containing a term in standard prefix notation without module qualifiers into the corresponding data term.
readsTerm :: String -> [(a,String)]   
For backward compatibility.
readTerm :: String -> a   
For backward compatibility.
readsQTerm :: String -> [(a,String)]   
Transforms a string containing a term in standard prefix notation with qualified constructor names into the corresponding data term.
readQTerm :: String -> a   
Transforms a string containing a term in standard prefix notation with qualified constructor names into the corresponding data term.
readQTermFile :: String -> IO a   
Reads a file containing a string representation of a term in standard prefix notation and returns the corresponding data term.
readQTermListFile :: String -> IO [a]   
Reads a file containing lines with string representations of terms of the same type and returns the corresponding list of data terms.
writeQTermFile :: String -> a -> IO ()   
Writes a ground term into a file in standard prefix notation.
writeQTermListFile :: String -> [a] -> IO ()   
Writes a list of ground terms into a file.

Exported operations:

showTerm :: a -> String   

Transforms a ground(!) term into a string representation in standard prefix notation. Thus, showTerm suspends until its argument is ground. This function is similar to the prelude function show but can read the string back with readUnqualifiedTerm (provided that the constructor names are unique without the module qualifier).

showQTerm :: a -> String   

Transforms a ground(!) term into a string representation in standard prefix notation. Thus, showTerm suspends until its argument is ground. Note that this function differs from the prelude function show since it prefixes constructors with their module name in order to read them back with readQTerm.

readsUnqualifiedTerm :: [String] -> String -> [(a,String)]   

Transform a string containing a term in standard prefix notation without module qualifiers into the corresponding data term. The first argument is a non-empty list of module qualifiers that are tried to prefix the constructor in the string in order to get the qualified constructors (that must be defined in the current program!). In case of a successful parse, the result is a one element list containing a pair of the data term and the remaining unparsed string.

readUnqualifiedTerm :: [String] -> String -> a   

Transforms a string containing a term in standard prefix notation without module qualifiers into the corresponding data term. The first argument is a non-empty list of module qualifiers that are tried to prefix the constructor in the string in order to get the qualified constructors (that must be defined in the current program!).

Example: readUnqualifiedTerm ["Prelude"] "Just 3" evaluates to (Just 3)

readsTerm :: String -> [(a,String)]   

For backward compatibility. Should not be used since their use can be problematic in case of constructors with identical names in different modules.

readTerm :: String -> a   

For backward compatibility. Should not be used since their use can be problematic in case of constructors with identical names in different modules.

readsQTerm :: String -> [(a,String)]   

Transforms a string containing a term in standard prefix notation with qualified constructor names into the corresponding data term. In case of a successful parse, the result is a one element list containing a pair of the data term and the remaining unparsed string.

readQTerm :: String -> a   

Transforms a string containing a term in standard prefix notation with qualified constructor names into the corresponding data term.

readQTermFile :: String -> IO a   

Reads a file containing a string representation of a term in standard prefix notation and returns the corresponding data term.

readQTermListFile :: String -> IO [a]   

Reads a file containing lines with string representations of terms of the same type and returns the corresponding list of data terms.

writeQTermFile :: String -> a -> IO ()   

Writes a ground term into a file in standard prefix notation.

Example call:
(writeQTermFile filename term)
Parameters:
  • filename : The name of the file to be written.
  • term : The term to be written to the file as a string.

writeQTermListFile :: String -> [a] -> IO ()   

Writes a list of ground terms into a file. Each term is written into a separate line which might be useful to modify the file with a standard text editor.

Example call:
(writeQTermListFile filename terms)
Parameters:
  • filename : The name of the file to be written.
  • terms : The list of terms to be written to the file.