liboleg-2010.1.2: A collection of Oleg Kiselyov's Haskell modules (2008-2010)

Text.PrintScanF

Description

The final view to the typed sprintf and sscanf

http://okmij.org/ftp/typed-formatting/FPrintScan.html

This code defines a simple domain-specific language of string patterns and demonstrates two interpreters of the language: for building strings (sprintf) and parsing strings (sscanf). This code thus solves the problem of typed printf/scanf sharing the same format string posed by Chung-chieh Shan. This code presents scanf/printf interpreters in the final style; it is thus the dual of the code in PrintScan.hs

Version: The current version is 1.1, Sep 2, 2008.

References

Documentation

class FormattingSpec repr whereSource

Methods

lit :: String -> repr a aSource

int :: repr a (Int -> a)Source

char :: repr a (Char -> a)Source

fpp :: PrinterParser b -> repr a (b -> a)Source

(^) :: repr b c -> repr a b -> repr a cSource

data PrinterParser a Source

Constructors

PrinterParser (a -> String) (String -> Maybe (a, String)) 

fmt :: (FormattingSpec repr, Show b, Read b) => b -> repr a (b -> a)Source

newtype FPr a b Source

Constructors

FPr ((String -> a) -> b) 

Instances

newtype FSc a b Source

Constructors

FSc (String -> b -> Maybe (a, String)) 

Instances

sscanf :: String -> FSc a b -> b -> Maybe aSource