Last active
December 18, 2015 21:49
-
-
Save scvalex/5850172 to your computer and use it in GitHub Desktop.
Make strings work like printf.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23. Hello, World! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings, FlexibleInstances, UndecidableInstances #-} | |
{-# OPTIONS_GHC -fno-warn-orphans #-} | |
import Data.String ( IsString(..) ) | |
import Text.Printf ( PrintfType, printf ) | |
instance (PrintfType a) => IsString a where | |
fromString s = printf s | |
main :: IO () | |
main = do | |
let x = 23 :: Int | |
s = "World!" :: String | |
"%d. Hello, %s\n" x s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The associated blog post is here.