[Haskell-cafe] flipped IO sequence

Cetin Sert cetin.sert at gmail.com
Wed Oct 1 06:18:15 EDT 2008


warn :: String → IO Int
warn = return 1 << putStrLn            -- causes an error
  -- = \msg → return 1 << putStrLn msg -- works just fine
  -- = \msg → putStrLn msg >> return 1 -- works just fine

(<<) :: Monad m ⇒ m b → m a → m b
b << a = a >>= \_ → b

Why do I get this compile-time error?? How can one define << ?

cetin at linux-d312:~/lab/test/qths/p> ghc -fglasgow-exts -O2 -o d64x --make
demo2.hs system.hs
[1 of 2] Compiling Netman.System    ( system.hs, system.o )

system.hs:23:14:
    No instance for (Num (IO Int))
      arising from the literal `1' at system.hs:23:14
    Possible fix: add an instance declaration for (Num (IO Int))
    In the first argument of `return', namely `1'
    In the first argument of `(<<)', namely `return 1'
    In the expression: return 1 << putStrLn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081001/354e8c46/attachment.htm


More information about the Haskell-Cafe mailing list