Daniel Trstenjak | 7 Nov 12:52 2013
Picon

GHC error message on type mismatch


Hello,

I don't know if I'm the only one struggeling with this GHC error message
on type mismatches or it's because I'm not a full time Haskeller, or
because I'm not a native english speaker.

Couldn't match type `A' with `B´
    Expected type: B
      Actual type: A

My problem is with 'Expected' and 'Actual', that I'm often unsure if
the compiler is "expecting" something or if I'm the expecting one
and the same goes for "actual".

I know that the compiler is the expecting one and that I'm given the
actual thing, but it's quite often that I'm looking at this error
and have to repeat this reasoning.

It's strange, because normaly I can memorize such things quite good,
but this one bothers me.

Perhaps it would be easier for myself if 'Actual type' would be called
e.g. 'Given type', I don't know, that just one of the two has a less
generic meaning.

Greetings,
Daniel
David Luposchainsky | 7 Nov 13:22 2013

Re: GHC error message on type mismatch

On 2013-11-07 12:52, Daniel Trstenjak wrote:
> My problem is with 'Expected' and 'Actual', that I'm often unsure if
> the compiler is "expecting" something or if I'm the expecting one
> and the same goes for "actual".

Funny you mention it; I think I just got too used to the fact that every
time I see this error I have to take a step back to remember what it
means exactly. Renaming it to "given" or "provided" would really help.

+1

David
Simon Peyton-Jones | 7 Nov 15:02 2013
Picon

RE: GHC error message on type mismatch

The motivation is this. Consider

	f True

where f :: Int -> Char

Then 
  f *expects* an argument of type Int
  but the *actual* argument has type Bool

Does that help?

Simon

| -----Original Message-----
| From: Glasgow-haskell-users [mailto:glasgow-haskell-users-
| bounces <at> haskell.org] On Behalf Of David Luposchainsky
| Sent: 07 November 2013 12:23
| To: Daniel Trstenjak; glasgow-haskell-users <at> haskell.org
| Subject: Re: GHC error message on type mismatch
| 
| On 2013-11-07 12:52, Daniel Trstenjak wrote:
| > My problem is with 'Expected' and 'Actual', that I'm often unsure if
| > the compiler is "expecting" something or if I'm the expecting one
| > and the same goes for "actual".
| 
| Funny you mention it; I think I just got too used to the fact that every
| time I see this error I have to take a step back to remember what it
| means exactly. Renaming it to "given" or "provided" would really help.
| 
(Continue reading)

David Fox | 7 Nov 15:21 2013

Re: GHC error message on type mismatch

It *is* sometimes difficult to remember that my expectations and I are not part of this equation - it might be a better prompt to say something like

   type mismatch between function parameter and supplied value:
      function parameter type: A
      supplied value type: B


On Thu, Nov 7, 2013 at 6:02 AM, Simon Peyton-Jones <simonpj <at> microsoft.com> wrote:
The motivation is this. Consider

        f True

where f :: Int -> Char

Then
  f *expects* an argument of type Int
  but the *actual* argument has type Bool

Does that help?

Simon

| -----Original Message-----
| From: Glasgow-haskell-users [mailto:glasgow-haskell-users-
| bounces <at> haskell.org] On Behalf Of David Luposchainsky
| Sent: 07 November 2013 12:23
| To: Daniel Trstenjak; glasgow-haskell-users <at> haskell.org
| Subject: Re: GHC error message on type mismatch
|
| On 2013-11-07 12:52, Daniel Trstenjak wrote:
| > My problem is with 'Expected' and 'Actual', that I'm often unsure if
| > the compiler is "expecting" something or if I'm the expecting one
| > and the same goes for "actual".
|
| Funny you mention it; I think I just got too used to the fact that every
| time I see this error I have to take a step back to remember what it
| means exactly. Renaming it to "given" or "provided" would really help.
|
| +1
|
| David
|
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users <at> haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Daniel Trstenjak | 8 Nov 05:54 2013
Picon

Re: GHC error message on type mismatch


Hi Simon,

On Thu, Nov 07, 2013 at 02:02:06PM +0000, Simon Peyton-Jones wrote:
> The motivation is this. Consider
> 
> 	f True
> 
> where f :: Int -> Char
> 
> Then 
>   f *expects* an argument of type Int
>   but the *actual* argument has type Bool
> 
> Does that help?

If you would switch the meaning of 'Expected' and 'Actual', than it
still could make perfectly sense and my brain seems to tend to this
switched meaning.

I think my main issue is the word 'Actual'. I seem to associate
something more authoritative with this word and not just a wrongly given
type by the user, and on the other side 'Expected' doesn't feel authoritative
enough.

Yes, I think the combination of the words 'Expected' and 'Actual' is
irritating me and that I'm perceiving 'Actual' as the more authoritative one.

Perhaps:

Couldn't match type `A' with `B´
    Real  type: B
    Given type: A

Or instead of 'Given', like others have suggested: 'Provided' or 'Supplied'.

Greetings,
Daniel
Carter Schonwald | 8 Nov 06:19 2013
Picon

Re: GHC error message on type mismatch

i'm not sure how change the words to synonyms helps communicate the exact same thing better, :) 

That said, once you start digging into really really fancy types, you'll certainly discover examples where the error messages are confusing and need some care to better communicate what is indeed the error.

Point being: as you get into trying out really really fancy types, please feel welcome to  share examples where the resulting error messages seem lacking / down right confusing. (though asking for help on the cafe list or #haskell on irc first is probably the first place to go, of course)


On Thu, Nov 7, 2013 at 11:54 PM, Daniel Trstenjak <daniel.trstenjak <at> gmail.com> wrote:

Hi Simon,

On Thu, Nov 07, 2013 at 02:02:06PM +0000, Simon Peyton-Jones wrote:
> The motivation is this. Consider
>
>       f True
>
> where f :: Int -> Char
>
> Then
>   f *expects* an argument of type Int
>   but the *actual* argument has type Bool
>
> Does that help?

If you would switch the meaning of 'Expected' and 'Actual', than it
still could make perfectly sense and my brain seems to tend to this
switched meaning.

I think my main issue is the word 'Actual'. I seem to associate
something more authoritative with this word and not just a wrongly given
type by the user, and on the other side 'Expected' doesn't feel authoritative
enough.

Yes, I think the combination of the words 'Expected' and 'Actual' is
irritating me and that I'm perceiving 'Actual' as the more authoritative one.


Perhaps:

Couldn't match type `A' with `B´
    Real  type: B
    Given type: A


Or instead of 'Given', like others have suggested: 'Provided' or 'Supplied'.


Greetings,
Daniel
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Dan Frumin | 8 Nov 06:30 2013
Picon

Re: GHC error message on type mismatch


Hi everyone 

> On 07 Nov 2013, at 23:54, Daniel Trstenjak <daniel.trstenjak <at> gmail.com> wrote:
> 
> 
> Hi Simon,
> 
>> On Thu, Nov 07, 2013 at 02:02:06PM +0000, Simon Peyton-Jones wrote:
>> The motivation is this. Consider
>> 
>>    f True
>> 
>> where f :: Int -> Char
>> 
>> Then 
>>  f *expects* an argument of type Int
>>  but the *actual* argument has type Bool
>> 
>> Does that help?
> 
> If you would switch the meaning of 'Expected' and 'Actual', than it
> still could make perfectly sense and my brain seems to tend to this
> switched meaning.
> 

Yeah I can see how that may happen. 

f's argument type is *actually* an Int, but it was used in a way that caller *expects* it to have a type Bool

> I think my main issue is the word 'Actual'. I seem to associate
> something more authoritative with this word and not just a wrongly given
> type by the user, and on the other side 'Expected' doesn't feel authoritative
> enough.
> 
> Yes, I think the combination of the words 'Expected' and 'Actual' is
> irritating me and that I'm perceiving 'Actual' as the more authoritative one.
> 
> 
> Perhaps:
> 
> Couldn't match type `A' with `B´
>    Real  type: B
>    Given type: A
> 
> 
> Or instead of 'Given', like others have suggested: 'Provided' or 'Supplied'.
> 
> 
> Greetings,
> Daniel
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users <at> haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Roman Cheplyaka | 8 Nov 08:17 2013

Re: GHC error message on type mismatch

* Daniel Trstenjak <daniel.trstenjak <at> gmail.com> [2013-11-08 05:54:49+0100]
> Perhaps:
> 
> Couldn't match type `A' with `B´
>     Real  type: B
>     Given type: A
> 
> 
> Or instead of 'Given', like others have suggested: 'Provided' or 'Supplied'.

So far in this thread I haven't seen any suggestions better than status
quo.

E.g.:

  Prelude> (undefined :: Int -> Bool) (undefined :: Bool)

  <interactive>:2:29:
      Couldn't match expected type `Int' with actual type `Bool'
      In the first argument of `undefined :: Int -> Bool', namely
        `(undefined :: Bool)'
      In the expression: (undefined :: Int -> Bool) (undefined :: Bool)
      In an equation for `it':
          it = (undefined :: Int -> Bool) (undefined :: Bool)

This one is quite clear — the compiler expected an argument of type Int,
but it was of type Bool.

Now replace this with Real and Given. Well, Bool for the function
argument is both Real and Given (I gave it this type, and it became its
real type). And calling Int either Real or Given doesn't make any sense.

Roman
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users <at> haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Evan Laforge | 8 Nov 09:01 2013
Picon

Re: GHC error message on type mismatch

On Thu, Nov 7, 2013 at 4:22 AM, David Luposchainsky
<dluposchainsky <at> googlemail.com> wrote:
> On 2013-11-07 12:52, Daniel Trstenjak wrote:
>> My problem is with 'Expected' and 'Actual', that I'm often unsure if
>> the compiler is "expecting" something or if I'm the expecting one
>> and the same goes for "actual".
>
> Funny you mention it; I think I just got too used to the fact that every
> time I see this error I have to take a step back to remember what it
> means exactly. Renaming it to "given" or "provided" would really help.

For what it's worth, I used to have the same confusion.  But after a
few years it went away.  Now it seems obvious and I don't really
understand how I was confused before, or how I got unconfused.

That's the classic problem with trying to make anything intuitive.

When I write my own typecheck msgs, I always write "Function expected
X, but received Y."  That's not too far off from expected / actual,
though at least it has an explicit subject.
Daniel Trstenjak | 8 Nov 09:32 2013
Picon

Re: GHC error message on type mismatch


On Fri, Nov 08, 2013 at 12:01:13AM -0800, Evan Laforge wrote:
> When I write my own typecheck msgs, I always write "Function expected
> X, but received Y."  That's not too far off from expected / actual,
> though at least it has an explicit subject.

That's perfectly fine, because 'Function + expected' is pointing to the
compiler side and additionally 'received' is pointing to the user side.

Gmane