Guest User

Untitled

a guest
Dec 10th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import Text.Printf
  2.  
  3. myPutStrLn = putStrLn . (++) "log: "
  4.  
  5. -- GHC infers `myPrintf :: String -> IO ()' which is not what I want.
  6. myPrintf = logger . printf
  7. where
  8. -- note, this is just an example. should be replaceable with any function
  9. -- with this typesignature
  10. logger :: String -> IO ()
  11. logger = putStrLn . (++) "log: "
  12.  
  13. main = do
  14. -- Instead, I would like to write
  15. myPrintf "test %d" (23 :: Int)
  16. -- but it fails with
  17. {-hprintf.hs:26:3:
  18. The function `myPrintf' is applied to two arguments,
  19. but its type `String -> IO ()' has only one
  20. In a stmt of a 'do' block: myPrintf "test %d" 23
  21. In the expression:
  22. do { myPutStrLn "hello";
  23. myPutStrLn $ printf "test %d" (23 :: Int);
  24. myPrintf "test %d" 23 }
  25. In an equation for `main':
  26. main
  27. = do { myPutStrLn "hello";
  28. myPutStrLn $ printf "test %d" (23 :: Int);
  29. myPrintf "test %d" 23 }
  30. -}
Add Comment
Please, Sign In to add comment