Monday, January 26, 2015

haskell Data.Text.Format example

{-# LANGUAGE OverloadedStrings #-}

import Data.Text
import qualified Data.Text.Format as TF

main :: IO ()
main = do
     print $ TF.format "foo {}" $ TF.Only ("bar" :: Text)

     let str = "world" :: Text
     print $ TF.format strf $ TF.Only str

     let num = 123 :: Integer
     print $ TF.format multif (str, num)

strf :: TF.Format                                                                         
strf = "hello {}"                                                                         

multif :: TF.Format                                                                       
multif = "hello {} {}"

No comments: