Hoogle Search
Within LTS Haskell 24.50 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
-
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
type
Formatter = ArgKey -> ArgFmt -> Either SomeException Stringvformat Text.Format No documentation available.
-
what4 What4.Expr No documentation available.
-
what4 What4.Expr.App No documentation available.
-
what4 What4.Expr.Builder No documentation available.
-
what4 What4.Expr.VarIdentification No documentation available.
FormattedString :: Text -> Stringyaml-unscrambler YamlUnscrambler.Expectations Must conform to a textually described format.
ForeignFileHeaderPragma :: KindOfForeignCodeAgda Agda.Compiler.MAlonzo.Pragmas A pragma that must appear before the module header.