Module ReadShowTerm

Library for converting ground terms to strings and vice versa.

Remark: The Data type class constraint is removed for KiCS2 since this causes a memory leak (due to the non-deterministic method aValue) but it is not used in the implementation.

Author: Michael Hanus

Version: October 2024

Summary of exported operations:

showTerm :: Data a => a -> String  Deterministic 
Transforms a ground(!) data term into a string representation in standard prefix notation.
readsUnqualifiedTerm :: Data a => [String] -> String -> [(a,String)]  Deterministic 
Transform a string containing a data term in standard prefix notation without module qualifiers into the corresponding data term.
readUnqualifiedTerm :: Data a => [String] -> String -> a  Deterministic 
Transforms a string containing a data term in standard prefix notation without module qualifiers into the corresponding data term.

Exported operations:

showTerm :: Data a => a -> String  Deterministic 

Transforms a ground(!) data 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).

readsUnqualifiedTerm :: Data a => [String] -> String -> [(a,String)]  Deterministic 

Transform a string containing a data 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 :: Data a => [String] -> String -> a  Deterministic 

Transforms a string containing a data 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)