GHC error message on type mismatch

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

GHC error message on type mismatch

Daniel Trstenjak-2

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
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: GHC error message on type mismatch

David Luposchainsky
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
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

RE: GHC error message on type mismatch

Simon Peyton Jones
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-
| [hidden email]] On Behalf Of David Luposchainsky
| Sent: 07 November 2013 12:23
| To: Daniel Trstenjak; [hidden email]
| 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
| [hidden email]
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: GHC error message on type mismatch

David Fox-12
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 <[hidden email]> 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:[hidden email]
| [hidden email]] On Behalf Of David Luposchainsky
| Sent: 07 November 2013 12:23
| To: Daniel Trstenjak; [hidden email]
| 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
| [hidden email]
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: GHC error message on type mismatch

Daniel Trstenjak-2
In reply to this post by Simon Peyton Jones

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
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: GHC error message on type mismatch

Carter Schonwald
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 <[hidden email]> 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
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: GHC error message on type mismatch

Daniil Frumin
In reply to this post by Daniel Trstenjak-2

Hi everyone

> On 07 Nov 2013, at 23:54, Daniel Trstenjak <[hidden email]> 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
> [hidden email]
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: GHC error message on type mismatch

Roman Cheplyaka-2
In reply to this post by Daniel Trstenjak-2
* Daniel Trstenjak <[hidden email]> [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
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

signature.asc (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: GHC error message on type mismatch

Evan Laforge
In reply to this post by David Luposchainsky
On Thu, Nov 7, 2013 at 4:22 AM, David Luposchainsky
<[hidden email]> 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.
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: GHC error message on type mismatch

Daniel Trstenjak-2

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.
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users