Copyright | (c) 2013 Chris Done, 2013 Shachaf Ben-Kiki |
---|---|
License | BSD3 |
Maintainer | chrisdone@gmail.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell98 |
Formatting functions.
- text :: Format Text
- stext :: Format Text
- string :: Format String
- shown :: Show a => Format a
- char :: Format Char
- builder :: Format Builder
- fconst :: Builder -> Format a
- int :: Integral a => Format a
- float :: Real a => Format a
- expt :: Real a => Int -> Format a
- fixed :: Real a => Int -> Format a
- prec :: Real a => Int -> Format a
- sci :: Format Scientific
- scifmt :: FPFormat -> Maybe Int -> Format Scientific
- shortest :: Real a => Format a
- groupInt :: (Buildable n, Integral n) => Int -> Char -> Format n
- commas :: (Buildable n, Integral n) => Format n
- ords :: Integral n => Format n
- plural :: (Num a, Eq a) => Text -> Text -> Format a
- asInt :: Enum a => Format a
- left :: Buildable a => Int -> Char -> Format a
- right :: Buildable a => Int -> Char -> Format a
- center :: Buildable a => Int -> Char -> Format a
- fitLeft :: Buildable a => Int -> Format a
- fitRight :: Buildable a => Int -> Format a
- base :: Integral a => Int -> Format a
- bin :: Integral a => Format a
- oct :: Integral a => Format a
- hex :: Integral a => Format a
- prefixBin :: Integral a => Format a
- prefixOct :: Integral a => Format a
- prefixHex :: Integral a => Format a
- build :: Buildable a => Format a
- class Buildable p
Text/string types
Numbers
float :: Real a => Format a Source
Render some floating point with the usual notation, e.g. 123.32 => "123.32"
expt :: Real a => Int -> Format a Source
Render a floating point number using scientific/engineering notation (e.g. 2.3e123), with the given number of decimal places.
fixed :: Real a => Int -> Format a Source
Render a floating point number using normal notation, with the given number of decimal places.
prec :: Real a => Int -> Format a Source
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.
sci :: Format Scientific Source
Render a scientific number.
shortest :: Real a => Format a Source
Render a floating point number using the smallest number of digits that correctly represent it.
groupInt :: (Buildable n, Integral n) => Int -> Char -> Format n Source
Group integral numbers, e.g. groupInt 2 .
on 123456 -> "12.34.56".
commas :: (Buildable n, Integral n) => Format n Source
Add commas to an integral, e.g 12000 -> "12,000".
asInt :: Enum a => Format a Source
Shows the Int value of Enum instances using fromEnum
.
>>>
format ("Got: " % char % " (" % asInt % ")") 'a' 'a'
"Got: a (97)"
Padding
left :: Buildable a => Int -> Char -> Format a Source
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 -> Format a Source
Pad the right hand side of a string until it reaches k characters wide, if necessary filling with character c.
center :: Buildable a => Int -> Char -> Format a Source
Pad the left & right hand side of a string until it reaches k characters wide, if necessary filling with character c.
Bases
bin :: Integral a => Format a Source
Render an integer using binary notation. (No leading 0b is
added.) Defined as bin =
.base
2
oct :: Integral a => Format a Source
Render an integer using octal notation. (No leading 0o is
added.) Defined as oct =
.base
8
hex :: Integral a => Format a Source
Render an integer using hexadecimal notation. (No leading 0x is added.) Has a specialized implementation.
prefixBin :: Integral a => Format a Source
Render an integer using binary notation with a leading 0b.
prefixHex :: Integral a => Format a Source
Render an integer using hexadecimal notation with a leading 0x.
Buildables
class Buildable p
The class of types that can be rendered to a Builder
.