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.

  1. data Format1

    vformat Text.Format

    A variant of Format, it transforms all argument's key to Nest (Index 0) key

  2. class FormatArg a

    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

    1. Can not find argument for the given key.
    2. 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.99
    
    Note: Since v0.12.0, FormatTime instance has been remove, use vformat-time instead.

  3. class FormatType t

    vformat Text.Format

    A typeclass provides the variable arguments magic for format

  4. type Formatter = ArgKey -> ArgFmt -> Either SomeException String

    vformat Text.Format

    No documentation available.

  5. Forall :: forall t (tp1 :: BaseType) (e :: BaseType -> Type) . !ExprBoundVar t tp1 -> !e BaseBoolType -> NonceApp t e 'BaseBoolType

    what4 What4.Expr

    No documentation available.

  6. Forall :: forall t (tp1 :: BaseType) (e :: BaseType -> Type) . !ExprBoundVar t tp1 -> !e BaseBoolType -> NonceApp t e 'BaseBoolType

    what4 What4.Expr.App

    No documentation available.

  7. Forall :: forall t (tp1 :: BaseType) (e :: BaseType -> Type) . !ExprBoundVar t tp1 -> !e BaseBoolType -> NonceApp t e 'BaseBoolType

    what4 What4.Expr.Builder

    No documentation available.

  8. ForallBound :: BoundQuant

    what4 What4.Expr.VarIdentification

    No documentation available.

  9. FormattedString :: Text -> String

    yaml-unscrambler YamlUnscrambler.Expectations

    Must conform to a textually described format.

  10. ForeignFileHeaderPragma :: KindOfForeignCode

    Agda Agda.Compiler.MAlonzo.Pragmas

    A pragma that must appear before the module header.

Page 320 of many | Previous | Next