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 #

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

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

Constructors

a :+ b infixr 1 
Instances
(Eq a, Eq b) => Eq (a :+ b) # 
Instance details

Defined in Text.Scanf.Internal

Methods

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

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

(Ord a, Ord b) => Ord (a :+ b) # 
Instance details

Defined in Text.Scanf.Internal

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 a, Show b) => Show (a :+ b) # 
Instance details

Defined in Text.Scanf.Internal

Methods

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

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

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

data Format t where #

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) # 
Instance details

Defined in Text.Scanf.Internal

Methods

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

show :: Format t -> String #

showList :: [Format t] -> ShowS #

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

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 :+ Format :+ Int :+ Format :+ ())

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

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 #

Append a constant string to a format string.

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

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

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

Append a constant whitespace string to a format string.

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

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

Format an Integer.

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

Format an Int.

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

Format a Double.

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

Format a Format.

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

Format a Format.

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

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

Parse a string according to a format string.

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

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

Print a string according to a format string.

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