Type checker's expected and inferred types (reformatted)

Isaac Dupree ml at isaac.cedarswampstudios.org
Fri Oct 23 21:46:36 EDT 2009

C Rodrigues wrote:
> 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 ().

Which message do you prefer? I couldn't tell which it was.

For myself, I never understood the difference between "expected" and 
"inferred": it works better for me to just think "there were at least 
two different ways that determined the 'type' of this expression, and 
the results contradicted each other, and here are two of those results. 
  Now, dear user, go and look at your code to intuit *what* those ways 
of determining the type might have been" (or sometimes it's easier just 
to look for mistakes, ignoring the particular details of the error)


More information about the Glasgow-haskell-users mailing list