I came across a type error that misled me for quite a while, because the
expected and inferred types were backwards (from my point of view). A
simplified example is below. Can someone explain how GHC's type checker
creates the error message?
In this example, fun1 and fun2 are basically the same. The type error is
because they try to run an IO () together with a Maybe ().
> import Control.Monad>> foo :: Maybe ()> foo = return ()>> bar :: IO ()> bar =
> return ()>> fun1 = let fooThen m = foo >> m> in fooThen (bar >>
> undefined)>> fun2 = let fooThen m = foo >> m> in fooThen (do {bar;
> undefined})
With ghc 6.10.4, both functions attribute the error message to `bar'. However,
the expected and inferred monads are swapped.fun1 produces the error
message:Couldn't match expected type `Maybe a' against inferred type `IO ()'In
the first argument of `(>>=)', namely `bar'fun2 produces the error
message:Couldn't match expected type `IO ()' against inferred type `Maybe ()'In
a stmt of a 'do' expression: bar
It's confusing because 'bar' is inferred to have type Maybe (), even though
it's explicitly declared to be an IO ().
_________________________________________________________________
New Windows 7: Find the right PC for you. Learn more.
http://www.microsoft.com/windows/pc-scout/default.aspx?CBID=wl&ocid=PID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_pcscout:102009
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users