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

minh thu noteed at gmail.com
Mon Oct 12 12:44:55 EDT 2009


2009/10/12 michael rice <nowgate at yahoo.com>

>  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
>
>
>
Both seem good to me and my old ghci (6.6.1)...

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


More information about the Haskell-Cafe mailing list