Hoogle Search
Within LTS Haskell 24.38 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
FormactionA :: Attribute "formaction" 'False 'Falsetype-of-html Html.Type No documentation available.
FormenctypeA :: Attribute "formenctype" 'False 'Falsetype-of-html Html.Type No documentation available.
FormmethodA :: Attribute "formmethod" 'False 'Falsetype-of-html Html.Type No documentation available.
FormnovalidateA :: Attribute "formnovalidate" 'False 'Truetype-of-html Html.Type No documentation available.
FormtargetA :: Attribute "formtarget" 'False 'Falsetype-of-html Html.Type No documentation available.
-
This library is inspired by Python's str.format and Haskell's Text.Printf, and most of the features are copied from these two libraries.
-
vformat Text.Format A data type indicates a format string Format string contains "replacement fields" surrounded by curly braces {}. Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling {{ and }}.
Format string syntax
format -> {chars | ("{" [key][":"fmt] "}")} key -> <see ArgKey> fmt -> <see ArgFmt>Note: This library use a description language to describe syntax, see next section. Note: A key can be omitted only if there is no explict index key before it, it will be automatically caculated and inserted to the format string according to its position in the omitted key sequence. Examples>>> "I like {coffee}, I drink it everyday." :: Format >>> "{no:<20} {name:<20} {age}" :: Format >>> "{{\"no\": {no}, \"name\": \"{name}\"}}" :: FormatSyntax description language
A syntax expr may contain a list of fields as followingsidentifier identifier of an expr <description> use natural language as an expr -> use right hand expr to describe identifier () a required field, may be omitted [] an optional field {} repeat any times of the field | logical or, choice between left and right "" literal textBuilt-in exprschar -> <any character> chars -> {char} int -> <integer without sign> -
vformat Text.Format A variant of Format, it transforms all argument's key to Nest (Index 0) key
-
vformat Text.Format Typeclass of formatable values. The formatArg method takes a value, a key and a field format descriptor and either fails due to a ArgError or produce a string as the result. There is a default formatArg for Generic instances, which applies defaultOptions to genericFormatArg. There are two reasons may cause formatting fail
- Can not find argument for the given key.
- The field format descriptor does not match the argument.
Extending to new types
Those format functions can be extended to format types other than those provided by default. This is done by instantiating FormatArg. Examples{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} import Control.Exception import GHC.Generics import Text.Format -- Manually extend to () instance FormatArg () where formatArg x k fmt@(ArgFmt{fmtSpecs="U"}) = let fmt' = fmt{fmtSpecs = ""} in formatArg (show x) k fmt' formatArg _ _ _ = Left $ toException ArgFmtError -- Use default generic implementation for type with nullary data constructors. data Color = Red | Yellow | Blue deriving Generic instance FormatArg Color -- Use default generic implementation for type with non-nullary data constructor. data Triple = Triple String Int Double deriving Generic instance FormatArg Triple -- Use default generic implementation for type using record syntax. data Student = Student { no :: Int , name :: String , age :: Int } deriving Generic instance FormatArg Student -- Customize field names data Book = Book { bookName :: String , bookAuthor :: String , bookPrice :: Double } instance FormatArg Book where formatArg x k fmt | k == mempty = return $ format1 "{name} {author} {price:.2f}" x | k == Name "name" = formatArg (bookName x) mempty fmt | k == Name "author" = formatArg (bookAuthor x) mempty fmt | k == Name "price" = formatArg (bookPrice x) mempty fmt | otherwise = Left $ toException $ ArgKeyError -- A better way to customize field names -- instance FormatArg Book where -- formatArg = genericFormatArg $ -- defaultOptions { fieldLabelModifier = drop 4 } main :: IO () main = do putStrLn $ format "A unit {:U}" () putStrLn $ format "I like {}." Blue putStrLn $ format "Triple {0!0} {0!1} {0!2}" $ Triple "Hello" 123 pi putStrLn $ format1 "Student: {no} {name} {age}" $ Student 1 "neo" 30 putStrLn $ format "A book: {}" $ Book "Math" "nobody" 99.99 putStrLn $ format1 "Book: {name}, Author: {author}, Price: {price:.2f}" $ Book "Math" "nobody" 99.99Note: Since v0.12.0, FormatTime instance has been remove, use vformat-time instead. -
vformat Text.Format A typeclass provides the variable arguments magic for format