Module Data.Format

The library provides some operations to format values of basic data types with arbitrary flags similarly to the printf statement of C.

These operations are used for the translation of integrated code with the format tag to replace the format specifiers.

This library follows the C specification for the formatting. This specification may be found at http://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html

Author: Jasper Sikorra - jsi@informatik.uni-kiel.de

Version: December 2020

Summary of exported operations:

showChar :: Char -> Maybe String -> Maybe Int -> Maybe Int -> Char -> String  Deterministic 
The function showChar formats a character
showInt :: Char -> Maybe String -> Maybe Int -> Maybe Int -> Int -> String  Deterministic 
The function showInt formats an Int
showFloat :: Char -> Maybe String -> Maybe Int -> Maybe Int -> Float -> String  Deterministic 
The function showFloat formats a Float
showString :: Char -> Maybe String -> Maybe Int -> Maybe Int -> String -> String  Deterministic 
The function showString formats a String

Exported operations:

showChar :: Char -> Maybe String -> Maybe Int -> Maybe Int -> Char -> String  Deterministic 

The function showChar formats a character

Example call:
(showChar type flags width precision char)
Parameters:
  • type : will be ignored
  • flags : a string, everything but the minus char will be ignored
  • width : the minimal number of characters to be printed
  • precision : will be ignored
  • char : The char which should be formatted
Returns:
A string containing the formatted character

showInt :: Char -> Maybe String -> Maybe Int -> Maybe Int -> Int -> String  Deterministic 

The function showInt formats an Int

Example call:
(showInt t mf mw mp i)
Parameters:
  • t : A char setting the way of number representation
  • mf : A string containing all flags
  • mw : The minimal number of characters to be printed
  • mp : The minimal number of numbers to be printed
  • i : The Int which should be formatted
Returns:
A string containing the formatted Int

showFloat :: Char -> Maybe String -> Maybe Int -> Maybe Int -> Float -> String  Deterministic 

The function showFloat formats a Float

Example call:
(showFloat t mf mw mp x)
Parameters:
  • t : A char setting wether to use an exponent or not
  • mf : A string containing all flags
  • mw : The minimal number of characters to be printed before the point
  • mp : The exact amount of numbers to be printed after the point
  • x : The Float which should be formatted
Returns:
A string containing the formatted float

showString :: Char -> Maybe String -> Maybe Int -> Maybe Int -> String -> String  Deterministic 

The function showString formats a String

Example call:
(showString t mf mw mp s)
Parameters:
  • t : Ignored
  • mf : A string containing all flags
  • mw : The minimal number of characters to be printed
  • mp : The exact number of characters of the string to be printed
  • s : The String which should be formatted
Returns:
A string containing the formatted String