[Haskell-cafe] Strange type error with associated type synonyms

Max Rabkin max.rabkin at gmail.com
Wed May 27 16:14:50 EDT 2009


On Wed, May 27, 2009 at 9:59 PM, Bulat Ziganshin
<bulat.ziganshin at gmail.com> wrote:
> Hello Simon,
>
> Wednesday, May 27, 2009, 11:42:22 PM, you wrote:
>
> while we are here - i always had problems understanding what is
> inferred and what is expected type. may be problem is just that i'm
> not native speaker
>
> are other, especially beginners, had the same problem?

The inferred type of e is the type that the compiler thinks e has. The
expected type is the type it *should* have, given its context.

Consider:

f :: Int -> Int

then the expression (f True) has a type error:

    Couldn't match expected type `Int' against inferred type `Bool'
    In the first argument of `f', namely `True'

GHC is saying the first argument of f *should* be an Int, but it seems
to be a Bool.

As to whether it's confusing, I sometimes have to read these messages
a few times (sometimes it's unclear which expression is being referred
to, or why GHC thinks that the expression has a certain type), but the
words themselves are clear in their meaning to me.

HTH,
Max


More information about the Haskell-Cafe mailing list