
On Sun, 2010-01-03 at 23:21 +0100, Francesco Guerrieri wrote:
On Sun, Jan 3, 2010 at 11:06 PM, Rahul Kapoor
wrote: I am not sure I completely understand your question (I think I do)
It appears that you did. Thanks!
ghci is able to infer that the Monad's in question are the Maybe and List respectively. In (almost?) all cases type inference allows the compiler to pick which overloaded implementation is to be used.
Why did you put the "almost"? Given the types on which the function is acting, either it finds a good match or not, in which case it is a compile-time error. What am I missing?
That further it may be lost (if I misunderstood the question then sorry). liftM a b will now the correct monad as long as: 1. It knows monad in second parameter or 2. It knows monad in result Knowing (or defaulting in case of GHCi) is sufficient.
and do poor haskell programmers never feel the need to explicitly state to which monad they "wish to lift" ?
It is probably a matter of taste - but adding type signatures even in the presence of type inference is usually a good thing except for the most trivial cases It serves as a documentation and a quick test by making sure that the compiler and you infer the same type since it is a compile error to specify a type which is not compatible with what the compiler infers.
Well. As far as 'global' signatures (i.e. the ones directly in module) are concerned it is correct. However there is sometimes need to write something like:
sizeOf (undefined :: CInt) or map (show :: Int -> String) . map read
Great, I didn't recall that a wrong annotation was a compile error.
That's strong type system :) Regards