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 .<br>
<br>ghci> :t (>>=)<br>(>>=) :: (Monad m) => m a -> (a -> m b) -> m b<br><br>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.<br>
<br>Likewise,<br><br>ghci> :t (+)<br>(+) :: (Num a) => a -> a -> a<br><br>fromIntegral ((1 :: Int) + 2) + (3 :: Integer)<br>6<br><br>This shows clearly that the types are not the same along the "+ chain".<br>
<br><br><div class="gmail_quote">2009/10/12 michael rice <span dir="ltr"><<a href="mailto:nowgate@yahoo.com">nowgate@yahoo.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
Dumb! I just figured out I was entering the input string in quotes.<br><br>So, I suppose the answer to my question is yes, type CAN be changed along a >>= chain. I was having trouble doing it in a different problem, created this small example to illustrate the problem, and then screwed it up putting quotes around my input string.<br>
<br>Thanks!<br><br>Michael<br><br>--- On <b>Mon, 10/12/09, Niklas Broberg <i><<a href="mailto:niklas.broberg@gmail.com" target="_blank">niklas.broberg@gmail.com</a>></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;">
<br>From: Niklas Broberg <<a href="mailto:niklas.broberg@gmail.com" target="_blank">niklas.broberg@gmail.com</a>><br>Subject: Re: [Haskell-cafe] Can type be changed along a >>= chain?<br>To: "michael rice" <<a href="mailto:nowgate@yahoo.com" target="_blank">nowgate@yahoo.com</a>><br>
Cc: <a href="mailto:haskell-cafe@haskell.org" target="_blank">haskell-cafe@haskell.org</a><br>Date: Monday, October 12, 2009, 12:43 PM<br><br><div><div class="im">On Mon, Oct 12,
2009 at 6:37 PM, michael rice <span dir="ltr"><<a rel="nofollow" href="http://mc/compose?to=nowgate@yahoo.com" target="_blank">nowgate@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;" valign="top">
transform :: IO ()<br>transform = putStrLn "What is your digit
string?"<br> >> getLine<br> >>= \str -> return ('9':str)<br> >>= \str -> return (read str :: Int)<br> >>= \i -> putStrLn $ "The number is " ++ show i<br>
</td></tr></tbody></table></blockquote><div></div></div><div>This code works perfectly for me. What problem are you seeing specifically?<br></div><div></div><div>Cheers,</div><div></div><div>/Niklas</div>
</div></blockquote></td></tr></tbody></table><br>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>