Generate formatted strings in a type-safe way
{-# LANGUAGE TypeApplications, DataKinds #-}
module Main where
import Interpolation (printf)
data Person
= Person
{ name :: String
, age :: Int
} deriving Eq
instance Show Person where
show (Person name age) =
let
printPerson :: String -> Int -> String
printPerson = printf @"My name is %s, I am %d years old"
in
printPerson name age
main :: IO ()
main = print (Person "jimmy" 99)
-- My name is jimmy, I am 99 years old
cabal build
cabal run
- No
template-haskell
required - Right now only C-style formatting is supported
- Roadmap:
HasField
support- Other language string formatting syntaxes (e.g.
Nix
,rust
)