Created
August 25, 2012 13:15
-
-
Save lewurm/3465511 to your computer and use it in GitHub Desktop.
printf in function composition
This file contains hidden or 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
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