Re: Re[2]: [Haskell-cafe] Strange type error with associated type synonyms

2009-05-27 Thread Max Rabkin
On Wed, May 27, 2009 at 9:59 PM, Bulat Ziganshin
 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
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re[2]: [Haskell-cafe] Strange type error with associated type synonyms

2009-05-27 Thread Bulat Ziganshin
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?

> Claus made a suggestion about type error messages:

> | Apart from bracketing fully applied type synonyms, the error message
> | could be improved by providing the missing bit of information about
> | 'Memo':
> |
> | D:\home\Haskell\tmp\desktop\types.hs:11:11:
> | Couldn't match expected type `Memo d1'
> |against inferred type `Memo d'
> | (type Memo d :: * -> *)
> | In the second argument of `(.)', namely `appl'
> | In the expression: abst . appl
> | In the definition of `f': f = abst . appl

> I've implemented this idea; note the "NB" line below:

> NoMatchErr.hs:20:11:
> Couldn't match expected type `Memo d'
>against inferred type `Memo d1'
>   NB: `Memo' is a (non-injective) type function
> In the second argument of `(.)', namely `appl'
> In the expression: abst . appl
> In the definition of `f': f = abst . appl

> (Rather than give its kind, I thought it was better to focus on the
> reason for the mis-match, namely the non-injectivity.)

> Simon
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe