[Haskell-cafe] Can type be changed along a >>= chain?
Ketil Malde
ketil at malde.org
Mon Oct 12 15:14:45 EDT 2009
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.)
> Likewise,
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)
> 6
...but 'fromIntegral' converts it. Did I miss some subtle point here?
-k
--
If I haven't seen further, it is by standing in the footprints of giants
More information about the Haskell-Cafe
mailing list