Portability | GHC |
---|---|

Stability | experimental |

Maintainer | chrisdone@gmail.com |

Safe Haskell | None |

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

- type Format m a b = forall r. ((m -> r) -> a) -> (m -> r) -> b
- type Build a = forall r b. ((Builder -> r) -> b) -> (Builder -> r) -> a -> b
- type Wrap r m a t = ((m -> a) -> t) -> (r -> a) -> t
- now :: Monoid m => m -> Format m a a
- later :: Monoid m => (a -> m) -> Format m b (a -> b)
- wrap :: (m -> r) -> Wrap r m a t
- run :: Monoid f => Format f f a -> a
- ident :: Monoid m => ((m -> r) -> b) -> (m -> r) -> m -> b
- format :: Format Builder Text a -> a
- builder :: Format Builder Builder a -> a
- print :: Format Builder (IO ()) a -> a
- hprint :: Handle -> Format Builder (IO ()) a -> a
- build :: Buildable a => Build a
- text :: Build Text
- stext :: Build Text
- string :: Build String
- hex :: Build Integer
- expt :: Real a => Int -> Build a
- fixed :: Real a => Int -> Build a
- prec :: Real a => Int -> Build a
- shortest :: Real a => Build a
- left :: Buildable a => Int -> Char -> Build a
- right :: Buildable a => Int -> Char -> Build a
- data Text
- data Builder
- class Buildable p

# 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.

# Holey generators

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.

# Renderers

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

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

# General

# Integers

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 Text

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`

.

class Buildable p

The class of types that can be rendered to a `Builder`

.