[Haskell-beginners] GHC 6.12,
-fwarn-unused-do-bind and Text.Printf
daniel.is.fischer at web.de
Mon Feb 22 17:47:09 EST 2010
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
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
I'd probably use -fno-warn-unused-do-bind (as an OPTIONS_GHC pragma in the
> 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)?
More information about the Beginners