Skip to content

Instantly share code, notes, and snippets.

@lewurm
Created August 25, 2012 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewurm/3465511 to your computer and use it in GitHub Desktop.
Save lewurm/3465511 to your computer and use it in GitHub Desktop.
printf in function composition
import Text.Printf
myPutStrLn = putStrLn . (++) "log: "
-- GHC infers `myPrintf :: String -> IO ()' which is not what I want.
myPrintf = logger . printf
where
-- note, this is just an example. should be replaceable with any function
-- with this typesignature
logger :: String -> IO ()
logger = putStrLn . (++) "log: "
main = do
-- Instead, I would like to write
myPrintf "test %d" (23 :: Int)
-- but it fails with
{-hprintf.hs:26:3:
The function `myPrintf' is applied to two arguments,
but its type `String -> IO ()' has only one
In a stmt of a 'do' block: myPrintf "test %d" 23
In the expression:
do { myPutStrLn "hello";
myPutStrLn $ printf "test %d" (23 :: Int);
myPrintf "test %d" 23 }
In an equation for `main':
main
= do { myPutStrLn "hello";
myPutStrLn $ printf "test %d" (23 :: Int);
myPrintf "test %d" 23 }
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment