formatting-6.2.1: Combinator-based type-safe formatting (like printf() or FORMAT)

Safe HaskellSafe-Inferred
LanguageHaskell98

Formatting.Internal

Description

Internal format starters.

Synopsis

Documentation

newtype Format r a Source

A formatter. The r type means the returned value at the end. The more formatters you compose, the more this wil build up arguments from r to Int -> r to Char -> (Int -> r), etc.

Constructors

Format 

Fields

runFormat :: (Builder -> r) -> a
 

Instances

Category * Format

The same as (%). At present using Category has an import overhead, but one day it might be imported as standard.

(~) * a r => IsString (Format r a)

Useful instance for writing format string. With this you can write Foo instead of now "Foo!".

Monoid (Format r (a -> r))

Useful instance for applying two formatters to the same input argument. For example: format (year <> "/" % month) now will yield "2015/01".

(%) :: Format r a -> Format r' r -> Format r' a infixr 9 Source

Composition operator. Format is an instance of Category, but that is (at present) inconvenient to use with regular Prelude. So this function is provided as a convenience.

(%.) :: Format r (Builder -> r') -> Format r' a -> Format r a infixr 8 Source

Function compose two formatters. Will feed the result of one formatter into another.

now :: Builder -> Format r r Source

Insert a constant monoidal value.

bind :: Format r a -> (Builder -> Format r' r) -> Format r' a Source

Monadic indexed bind for holey monoids.

later :: (a -> Builder) -> Format r (a -> r) Source

Insert a function which accepts some argument and produces a Builder which is appended to the output at the end.

later (f :: Int -> Builder) produces Format r (Int -> r).

format :: Format Text a -> a Source

Run the formatter and return a lazy Text value.

sformat :: Format Text a -> a Source

Run the formatter and return a strict Text value.

bprint :: Format Builder a -> a Source

Run the formatter and return a Builder value.

fprint :: Format (IO ()) a -> a Source

Run the formatter and print out the text to stdout.

hprint :: Handle -> Format (IO ()) a -> a Source

Run the formatter and put the output onto the given Handle.

formatToString :: Format [Char] a -> a Source

Run the formatter and return a list of characters.