I would be very thankful if someone patient enough explained to me the situation below. It seems to me as if Haskell were ready to perform some kind of integral type coercion when returning a value from a function. On the other hand, I have read that Haskell does never convert a type implicitly.
If I type in GHCi:
> import Data.Word
> let t :: (Integer, Word32);
t = let { y = fromIntegral (-1) -- line breaks added for readability
; y' :: Integer
; y' = fromIntegral y } in (y', y)
GHCi tells me later that t = (-1,4294967295). But if I constrain the local y type specifically to Word32:
> let t :: (Integer, Word32);
t = let { y :: Word32
; y = fromIntegral (-1) -- line breaks added for readability
; y' :: Integer
; y' = fromIntegral y } in (y', y)
GHCi will tell me that t = (4294967295,4294967295).
I thought that if t's type is stated explicite as (Integer, Word32), GHCi will conclude that y' :: Integer and y :: Word32 since the function result is (y', y). Then, the type definition y :: Word32 would be completely unnecessary.
This all started when I tried to write a function to "safely" convert between Integral class members - e.g. Int -> Word32. That function was meant to return Just 1 when passed 1 and Nothing when passed -1.
A short search through SO and internet overall didn't provide me with any explanation.