HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Moduleformatting-7.2.0Haskell2010

Formatting.Formatters

Formatting functions.

Contents
  1. Text/string types
  2. Numbers
  3. Padding
  4. Bases
  5. Buildables
Synopsis
  • Packageformatting-7.2.0
  • Exports33
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceFormatters.hs

Text/string types

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

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

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

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

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

classclass Buildable p where

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

Instances38Buildable, …