Copyright | (c) 2013 Chris Done, 2013 Shachaf Ben-Kiki |
---|---|
License | BSD3 |
Maintainer | [email protected] |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell98 |
Formatting
Description
Combinator-based type-safe formatting (like printf() or FORMAT) for Text.
Example:
>>>
format ("Person's name is " % text % ", age is " % hex) "Dave" 54
See Formatting.Formatters for a complete list of formatting combinators.
- data Format r a
- (%) :: Format r a -> Format r' r -> Format r' a
- (%.) :: Format r (Builder -> r') -> Format r' a -> Format r a
- now :: Builder -> Format r r
- later :: (a -> Builder) -> Format r (a -> r)
- format :: Format Text a -> a
- sformat :: Format Text a -> a
- bprint :: Format Builder a -> a
- fprint :: Format (IO ()) a -> a
- hprint :: Handle -> Format (IO ()) a -> a
- module Formatting.Formatters
- formatToString :: Format [Char] a -> a
Documentation
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.
Instances
Category * Format | The same as (%). At present using |
(~) * a r => IsString (Format r a) | Useful instance for writing format string. With this you can
write |
Monoid (Format r (a -> r)) | Useful instance for applying two formatters to the same input
argument. For example: |
(%.) :: 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.
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)
.
Top-level functions
hprint :: Handle -> Format (IO ()) a -> a Source
Run the formatter and put the output onto the given Handle
.
Formatting library
module Formatting.Formatters
Other functions
formatToString :: Format [Char] a -> a Source
Run the formatter and return a list of characters.