holey-format-1.2.0: Combinator-based type-safe formatting (like printf() or FORMAT)

PortabilityGHC
Stabilityexperimental
Maintainerchrisdone@gmail.com
Safe HaskellNone

Text.Format

Contents

Description

Combinator-based type-safe formatting (like printf() or FORMAT) for Text.

Example:

 formatPerson =
   print (now "Person's name is " . ident . text . now ", age is " . hex . now "n")
         "Dave"
         "Jones"
         35

Synopsis

Documentation

type Format m a b = forall r. ((m -> r) -> a) -> (m -> r) -> bSource

Continuation based string formatter.

type Build a = forall r b. ((Builder -> r) -> b) -> (Builder -> r) -> a -> bSource

Builder formatting.

type Wrap r m a t = ((m -> a) -> t) -> (r -> a) -> tSource

Wrap the result with a function.

Holey generators

now :: Monoid m => m -> Format m a aSource

Append something to the output stream now.

later :: Monoid m => (a -> m) -> Format m b (a -> b)Source

Append something to the output stream, taking the value as an argument to a formatting function later.

wrap :: (m -> r) -> Wrap r m a tSource

Wrap the whole result in a function.

run :: Monoid f => Format f f a -> aSource

Run the formatter.

ident :: Monoid m => ((m -> r) -> b) -> (m -> r) -> m -> bSource

Identity on later.

Renderers

format :: Format Builder Text a -> aSource

Run the formatter and at the end extract a lazy Text from the Builder.

builder :: Format Builder Builder a -> aSource

Run the formatter producing a Builder.

print :: Format Builder (IO ()) a -> aSource

Run the formatter and print out the text to stdout.

hprint :: Handle -> Format Builder (IO ()) a -> aSource

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

General

build :: Buildable a => Build aSource

Include a buildable in the output stream.

text :: Build TextSource

Output a lazy text.

stext :: Build TextSource

Output a strict text.

string :: Build StringSource

Output a string.

Integers

hex :: Build IntegerSource

Render an integer using hexadecimal notation. (No leading 0x is added.) hex :: Build Integer

Floats

expt :: Real a => Int -> Build aSource

Render a floating point number using scientific/engineering notation (e.g. 2.3e123), with the given number of decimal places.

fixed :: Real a => Int -> Build aSource

Render a floating point number using normal notation, with the given number of decimal places.

prec :: Real a => Int -> Build aSource

Render a floating point number, with the given number of digits of precision. Uses decimal notation for values between 0.1 and 9,999,999, and scientific notation otherwise.

shortest :: Real a => Build aSource

Render a floating point number using the smallest number of digits that correctly represent it.

Padding

left :: Buildable a => Int -> Char -> Build aSource

Pad the left hand side of a string until it reaches k characters wide, if necessary filling with character c.

right :: Buildable a => Int -> Char -> Build aSource

Pad the right hand side of a string until it reaches k characters wide, if necessary filling with character c.

Re-exports

data Builder

A Builder is an efficient way to build lazy Text values. There are several functions for constructing builders, but only one to inspect them: to extract any data, you have to turn them into lazy Text values using toLazyText.

Internally, a builder constructs a lazy Text by filling arrays piece by piece. As each buffer is filled, it is 'popped' off, to become a new chunk of the resulting lazy Text. All this is hidden from the user of the Builder.