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

Modulefmt-0.6.3.0Haskell2010

Fmt.Internal.Template

Old-style formatting a la text-format.

  • 1 type
  • 1 class
  • 5 values
  • Packagefmt-0.6.3.0
  • Exports7
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceTemplate.hs
Example1 expression
import Fmt
valueformat :: (HasCallStack, FormatType r) => Format -> r
#

An old-style formatting function taken from text-format (see Data.Text.Format). Unlike Data.Text.Format.format from Data.Text.Format, it can produce String and strict Text as well (and print to console too). Also it's polyvariadic:

Example1 expression
format "{} + {} = {}" 2 2 42 + 2 = 4

You can use arbitrary formatters:

Example1 expression
format "0x{} + 0x{} = 0x{}" (hexF 130) (hexF 270) (hexF (130+270))0x82 + 0x10e = 0x190
newtypenewtype Format
#

A format string. This is intentionally incompatible with other string types, to make it difficult to construct a format string by concatenating string fragments (a very common way to accidentally make code vulnerable to malicious data).

This type is an instance of IsString, so the easiest way to construct a query is to enable the OverloadedStrings language extension and then simply write the query in double quotes.

{-# LANGUAGE OverloadedStrings #-}

import Fmt

f :: Format
f = "hello {}"

The underlying type is Text, so literal Haskell strings that contain Unicode characters will be correctly handled.

Constructors

Instances6Eq, Ord, Show, IsString, Semigroup, Monoid
  • Eq FormatDefined in fmt-0.6.3.0 · Fmt.Internal.Template
  • Ord FormatDefined in fmt-0.6.3.0 · Fmt.Internal.Template
  • Show FormatDefined in fmt-0.6.3.0 · Fmt.Internal.Template
  • IsString FormatDefined in fmt-0.6.3.0 · Fmt.Internal.Template
  • Semigroup FormatDefined in fmt-0.6.3.0 · Fmt.Internal.Template
  • Monoid FormatDefined in fmt-0.6.3.0 · Fmt.Internal.Template