scanf-0.1.0.0: Easy and type-safe format strings for parsing and printing

Safe HaskellSafe
LanguageHaskell2010

Text.Scanf.Internal

Synopsis

Documentation

data a :+ b infixr 1 Source #

A pretty pair type to build lists with values of different types. Remember to close lists with ().

3 :+ "14" :+ () :: Int :+ String :+ ()

Constructors

a :+ b infixr 1 

Instances

(Eq b, Eq a) => Eq ((:+) a b) Source # 

Methods

(==) :: (a :+ b) -> (a :+ b) -> Bool #

(/=) :: (a :+ b) -> (a :+ b) -> Bool #

(Ord b, Ord a) => Ord ((:+) a b) Source # 

Methods

compare :: (a :+ b) -> (a :+ b) -> Ordering #

(<) :: (a :+ b) -> (a :+ b) -> Bool #

(<=) :: (a :+ b) -> (a :+ b) -> Bool #

(>) :: (a :+ b) -> (a :+ b) -> Bool #

(>=) :: (a :+ b) -> (a :+ b) -> Bool #

max :: (a :+ b) -> (a :+ b) -> a :+ b #

min :: (a :+ b) -> (a :+ b) -> a :+ b #

(Show b, Show a) => Show ((:+) a b) Source # 

Methods

showsPrec :: Int -> (a :+ b) -> ShowS #

show :: (a :+ b) -> String #

showList :: [a :+ b] -> ShowS #

data Format t where Source #

Typed scanf/printf format strings. They can be built using the fmt quasiquote or with the fmt_ function and format combinators.

Constructors

Empty :: Format () 
Constant :: String -> Format t -> Format t 
Whitespace :: String -> Format t -> Format t 
Readable :: (Read a, Show a) => Format t -> Format (a :+ t) 
String :: Format t -> Format (String :+ t) 
Char :: Format t -> Format (Char :+ t) 

Instances

Show (Format t) Source # 

Methods

showsPrec :: Int -> Format t -> ShowS #

show :: Format t -> String #

showList :: [Format t] -> ShowS #

fmt_ :: (Format () -> Format t) -> Format t Source #

Construct a format string. This is an alternative to fmt that doesn't rely on Template Haskell.

The components of a format string are composed using (.) (function composition) and (%) (wrapper for constant strings).

fmt_ (int . " lazy " % string . " and " % int . " strict " % string)
  :: Format (Int :+ String :+ Int :+ String :+ ())

(%) :: String -> (Format t -> Format q) -> Format t -> Format q infixr 9 Source #

Append a constant string to a format string component.

N.B.: in scanf, spaces in the format string match any number of whitespace character until the next nonspace character.

constant :: String -> Format t -> Format t Source #

Append a constant string to a format string.

constant' :: String -> Format t -> Format t Source #

Append a constant string with no whitespace to a format string.

whitespace :: String -> Format t -> Format t Source #

Append a constant whitespace string to a format string.

readable :: (Read a, Show a) => Format t -> Format (a :+ t) Source #

integer :: Format t -> Format (Integer :+ t) Source #

Format an Integer.

int :: Format t -> Format (Int :+ t) Source #

Format an Int.

double :: Format t -> Format (Double :+ t) Source #

Format a Double.

string :: Format t -> Format (String :+ t) Source #

Format a String.

char :: Format t -> Format (Char :+ t) Source #

Format a Char.

readmap :: (a -> b) -> ReadS a -> ReadS b Source #

scanf :: Format t -> String -> Maybe t Source #

Parse a string according to a format string.

scanf [fmt|Hello %s|] "Hello world!" :: Maybe (String :+ ())
  = ("world!" :+ ())

printf :: Format t -> t -> String Source #

Print a string according to a format string.

printf [fmt|Hello %s|] ("everyone!" :+ ())
  = "Hello everyone!"