HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleformatting-7.2.0Haskell2010

Formatting.Formatters

Formatting functions.

  • 1 class
  • 32 values
  • Packageformatting-7.2.0
  • Exports33
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFormatters.hs

Text/string types

7 declarations
valueshown :: Show a => Format r (a -> r)
#

Output a showable value (instance of Show) by turning it into Text:

Example1 expression
format ("Value number " % shown % " is " % shown % ".") 42 False"Value number 42 is False."

Numbers

11 declarations
valueint :: Integral a => Format r (a -> r)
#

Render an integral e.g. 123 -> "123", 0 -> "0".

valuefloat :: Real a => Format r (a -> r)
#

Render some floating point with the usual notation, e.g. 123.32 => "123.32"

valuefixed :: Real a => Int -> Format r (a -> r)
#

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

valueshortest :: Real a => Format r (a -> r)
#

Render a floating point number using the smallest number of digits that correctly represent it. Note that in the case of whole numbers it will still add one decimal place, e.g. "1.0".

valueords :: Integral n => Format r (n -> r)
#

Add a suffix to an integral, e.g. 1st, 2nd, 3rd, 21st.

valueplural :: (Num a, Eq a) => Text -> Text -> Format r (a -> r)
#

English plural suffix for an integral.

For example:

Example4 expressions
:set -XOverloadedStringsformatPeople = format (int % " " <> plural "person" "people" % ".") :: Int -> Data.Text.Lazy.TextformatPeople 1"1 person."formatPeople 3"3 people."
valueasInt :: Enum a => Format r (a -> r)
#

Shows the Int value of Enum instances using fromEnum.

Example1 expression
format ("Got: " % char % " (" % asInt % ")") 'a' 'a'"Got: a (97)"

Padding

5 declarations
valueleft :: Buildable a => Int -> Char -> Format r (a -> r)
#

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

valueright :: Buildable a => Int -> Char -> Format r (a -> r)
#

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

valuecenter :: Buildable a => Int -> Char -> Format r (a -> r)
#

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

Bases

8 declarations
valuebin :: Integral a => Format r (a -> r)
#

Render an integer using binary notation. (No leading 0b is added.) Defined as bin = base 2.

valueoct :: Integral a => Format r (a -> r)
#

Render an integer using octal notation. (No leading 0o is added.) Defined as oct = base 8.

valuehex :: Integral a => Format r (a -> r)
#

Render an integer using hexadecimal notation. (No leading 0x is added.) Has a specialized implementation.

valuebytes
  1. :: (Ord f, Integral a, Fractional f)
  2. => Format Builder (f -> Builder)

    formatter for the decimal part

  3. -> Format r (a -> r)
#

Renders a given byte count using an appropiate decimal binary suffix:

Example1 expression
format (bytes shortest) 1024"1KB"
Example1 expression
format (bytes (fixed 2 % " ")) (1024*1024*5)"5.00 MB"

Buildables

2 declarations
classclass Buildable p where
#

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

Instances38Buildable, …