Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
Formatting.Internal
Description
Internal format starters.
Synopsis
- newtype Format r a = Format { }
- (%) :: Format r a -> Format r' r -> Format r' a
- (%.) :: Format r ( Builder -> r') -> Format r' a -> Format r a
- now :: Builder -> Format r r
- bind :: Format r a -> ( Builder -> Format r' r) -> Format r' a
- mapf :: (a -> b) -> Format r (b -> t) -> Format r (a -> t)
- 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
- formatToString :: Format [ Char ] a -> a
Documentation
A formatter. When you construct formatters the first type
parameter,
r
, will remain polymorphic. The second type
parameter,
a
, will change to reflect the types of the data that
will be formatted. For example, in
myFormat :: Formatter r (Text -> Int -> r) myFormat = "Person's name is " % text % ", age is " % hex
the first type parameter remains polymorphic, and the second type
parameter is
Text -> Int -> r
, which indicates that it formats a
Text
and an
Int
.
When you run the
Format
, for example with
format
, you provide
the arguments and they will be formatted into a string.
> format ("Person's name is " % text % ", age is " % hex) "Dave" 54 "Person's name is Dave, age is 36"
Instances
Functor ( Format r) Source # |
Not particularly useful, but could be. |
Category Format Source # |
The same as (%). At present using
|
a ~ r => IsString ( Format r a) Source # |
Useful instance for writing format string. With this you can
write
|
Defined in Formatting.Internal Methods fromString :: String -> Format r a Source # |
|
Semigroup ( Format r (a -> r)) Source # | |
Monoid ( Format r (a -> r)) Source # |
Useful instance for applying two formatters to the same input
argument. For example:
|
(%) :: Format r a -> Format r' r -> Format r' a infixr 9 Source #
Concatenate two formatters.
formatter1 % formatter2
is a formatter that accepts arguments for
formatter1
and
formatter2
and concatenates their results. For example
format1 :: Format r (Text -> r) format1 = "Person's name is " % text
format2 :: Format r r format2 = ", "
format3 :: Format r (Int -> r) format3 = "age is " % hex
myFormat :: Formatter r (Text -> Int -> r) myFormat = format1 % format2 % format3
Notice how the argument types of
format1
and
format3
are
gathered into the type of
myFormat
.
(This is actually the composition operator for
Format'
s
Category
instance, 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.
bind :: Format r a -> ( Builder -> Format r' r) -> Format r' a Source #
Monadic indexed bind for holey monoids.
mapf :: (a -> b) -> Format r (b -> t) -> Format r (a -> t) Source #
Functorial map over a formatter's input. Example:
format (mapf (drop 1) string) "hello"
later :: (a -> Builder ) -> Format r (a -> r) Source #
Format a value of type
a
using a function of type
a ->
. For example,
Builder
later (f :: Int -> Builder)
produces
Format r (Int -> r)
.
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.