
I hope you're not building some unneeded "rules" in your head. There is no
reason to believe there is something to be remembered about whether or not
"types can change along a >>= chain". That chain has nothing special in
Haskell. >>= is just an operator, much like ++, ! or .
ghci> :t (>>=)
(>>=) :: (Monad m) => m a -> (a -> m b) -> m b
This says that, you provide an a and you get a b. Nothing says the a and b
have to be the same upon successive uses.
Likewise,
ghci> :t (+)
(+) :: (Num a) => a -> a -> a
fromIntegral ((1 :: Int) + 2) + (3 :: Integer)
6
This shows clearly that the types are not the same along the "+ chain".
2009/10/12 michael rice
Dumb! I just figured out I was entering the input string in quotes.
= chain. I was having trouble doing it in a different problem, created
So, I suppose the answer to my question is yes, type CAN be changed along a this small example to illustrate the problem, and then screwed it up putting quotes around my input string.
Thanks!
Michael
--- On *Mon, 10/12/09, Niklas Broberg
* wrote: From: Niklas Broberg
Subject: Re: [Haskell-cafe] Can type be changed along a >>= chain? To: "michael rice" Cc: haskell-cafe@haskell.org Date: Monday, October 12, 2009, 12:43 PM On Mon, Oct 12, 2009 at 6:37 PM, michael rice
http://mc/compose?to=nowgate@yahoo.com wrote:
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
This code works perfectly for me. What problem are you seeing specifically? Cheers, /Niklas
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe