[Haskell-cafe] Can type be changed along a >>= chain?

michael rice nowgate at yahoo.com
Mon Oct 12 12:37:54 EDT 2009


The first of these works, but not the second. It would seem that the type cannot change along a >>= chain, but I may be missing something in the code.

Is the second example illegal? If so, is there a different way to change a String to an Int along the >>= chain?

Michael

===========

import Data.Char

{-
transform :: IO ()
transform = putStrLn "What is your word?"
         >> getLine
         >>= \str -> return ('Q':str)
         >>= \str -> return ('Z':str)
         >>= \str -> putStrLn $ "Transformed word is " ++ show str
-}

transform :: IO ()
transform = putStrLn "What is your digit string?"
         >> getLine
         >>= \str -> return ('9':str)
         >>= \str -> return (read str :: Int)
         >>= \i -> putStrLn $ "The number is " ++ show i




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091012/bdf6f33a/attachment.html


More information about the Haskell-Cafe mailing list