GHC 6.12, -fwarn-unused-do-bind and Text.Printf

Hi there, I'm trying to upgrade some code to ghc 6.12 but under -Wall, the new warning about unused do binds is triggering on Text.Printf.printf usage. This code: import Text.Printf main :: IO () main = do printf "Hello, world\n" printf "Hello the second time\n" When run with runhaskell -Wall gives: Warning: A do-notation statement discarded a result of type GHC.Prim.Any. Suppress this warning by saying "_ <- printf "Hello, world\n"", or by using the flag -fno-warn-unused-do-bind. Now, I'm confused why such a simple usage of printf triggers this warning; enforcing the first printf to type IO () fixes the warning, but it seems strange to no longer be able to simply write printf. Anyone knows a workaround, or can enlighten me what I'm doing wrong? A side question would be why we have "instance PrintfType (IO a)" instead of "instance PrintfType (IO ())"; what use is there for that generic type? Can printf return anything else than IO () (when used under IO at all)? thanks, iustin

Am Montag 22 Februar 2010 23:02:13 schrieb Iustin Pop:
Hi there,
I'm trying to upgrade some code to ghc 6.12 but under -Wall, the new warning about unused do binds is triggering on Text.Printf.printf usage.
This code:
import Text.Printf
main :: IO () main = do printf "Hello, world\n" printf "Hello the second time\n"
When run with runhaskell -Wall gives:
Warning: A do-notation statement discarded a result of type GHC.Prim.Any. Suppress this warning by saying "_ <- printf "Hello, world\n"", or by using the flag -fno-warn-unused-do-bind.
Now, I'm confused why such a simple usage of printf triggers this warning;
Because you don't bind the result of the first printf, which could be any type, so potentially interesting. The compiler doesn't know that 'printf fmt args' only ever returns undefined.
enforcing the first printf to type IO () fixes the warning,
Yep, the compiler knows that a return value of type () is uninteresting enough to be discarded without warning.
but it seems strange to no longer be able to simply write printf.
Anyone knows a workaround, or can enlighten me what I'm doing wrong?
a) one of the options the compiler offered b) expression type signature c) use (>>) to explicitly tell the compiler "I want to discard the return value" I'd probably use -fno-warn-unused-do-bind (as an OPTIONS_GHC pragma in the relevant files).
A side question would be why we have "instance PrintfType (IO a)" instead of "instance PrintfType (IO ())";
Very good question.
what use is there for that generic type? Can printf return anything else than IO () (when used under IO at all)?
thanks, iustin

On Mon, 22 Feb 2010 23:02:13 +0100, Iustin Pop
Hi there,
I'm trying to upgrade some code to ghc 6.12 but under -Wall, the new warning about unused do binds is triggering on Text.Printf.printf usage.
This code:
import Text.Printf
main :: IO () main = do printf "Hello, world\n" printf "Hello the second time\n"
When run with runhaskell -Wall gives:
Warning: A do-notation statement discarded a result of type GHC.Prim.Any. Suppress this warning by saying "_ <- printf "Hello, world\n"", or by using the flag -fno-warn-unused-do-bind.
Now, I'm confused why such a simple usage of printf triggers this warning; enforcing the first printf to type IO () fixes the warning, but it seems strange to no longer be able to simply write printf.
Anyone knows a workaround, or can enlighten me what I'm doing wrong?
What about providing a printf_ function with "IO ()" as return type? (like mapM vs mapM_) -- Nicolas Pouillard http://nicolaspouillard.fr

On Mon, Feb 22, 2010 at 11:02 PM, Iustin Pop
A side question would be why we have "instance PrintfType (IO a)" instead of "instance PrintfType (IO ())"; what use is there for that generic type? Can printf return anything else than IO () (when used under IO at all)?
I can only guess, but perhaps because "instance PrintfType (IO ())" would require the FlexibleInstances language extension. I believe the current implementation of printf is fully Haskell98.
participants (4)
-
Daniel Fischer
-
Iustin Pop
-
Nicolas Pouillard
-
Roel van Dijk