[Haskell-cafe] Can type be changed along a >>= chain?
noteed at gmail.com
Mon Oct 12 15:28:24 EDT 2009
2009/10/12 Ketil Malde <ketil at malde.org>:
> minh thu <noteed at gmail.com> writes:
>> 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.
> (But note that the monad 'm' has to be the same all the way. You can't
> switch from, say, IO to ST in the middle of the computation.)
> Contrariwise, I'd say.
>> ghci> :t (+)
>> (+) :: (Num a) => a -> a -> a
> I.e. (+) requires the same type on both sides...
>> fromIntegral ((1 :: Int) + 2) + (3 :: Integer)
> ...but 'fromIntegral' converts it. Did I miss some subtle point here?
I was talking about the types of the two + applications. They have a
different types, just like the >>= in the parent's message can have
different types. My fromIntegral has a role similar to the read s ::
Int of the original question.
More information about the Haskell-Cafe