Opened 5 years ago

Closed 5 years ago

#9901 closed bug (duplicate)

Error message: f is applied to two arguments, but its type has only two (sic)

Reported by: zardoz Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 7.8.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #9605 Differential Rev(s):
Wiki Page:

Description

I occasionally get type errors where the error message refers to a function’s arity in a contradictory way:

The function ‘X’ is applied to two arguments, […] but its type has only two.

Here’s a full error message of this kind:

lenstest.hs:89:12:

Couldn't match type ‘Either String Int’ with ‘Maybe b0’ Expected type: [Char] -> Either String Int

Actual type: [Char] -> Maybe b0

The function ‘preview’ is applied to two arguments, but its type ‘Getting (Data.Monoid.First b0) (Either b0 c0) b0

-> [Char] -> Maybe b0’

has only two In the second argument of ‘($)’, namely

‘(preview _Left "abc"
Either String Int)’ In a stmt of a 'do' block:
print $ (preview _Left "abc"
Either String Int)

Failed, modules loaded: none.

Attachments (1)

test.hs (600 bytes) - added by zardoz 5 years ago.
Testcase

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by simonpj

Would you care to give a test case?

comment:2 Changed 5 years ago by Yuras

It is hard to tell exactly without test case, but I'm almost sure it is a duplicate of #9605

comment:3 Changed 5 years ago by zardoz

Sorry, I lost track of this. I’ve attached a program which will reproduce this message on GHC 7.8.4. It doesn’t seem to relate to a forgotten do. It’s triggered by the wrong type annotation to the value of «preview».

comment:4 Changed 5 years ago by simonpj

Can you offer an example that does not depend on lens with its zillions of dependencies?

Usually you can just write down the types of the imports, thus:

preview :: <type of preview>
preview = error "urk"

Also is the UnicodeSyntax significant.

Thakns

Changed 5 years ago by zardoz

Attachment: test.hs added

Testcase

comment:5 Changed 5 years ago by zardoz

I’ve updated the attachment. Hopefully this should go through with just «base» installed.

I’m out of my depth on the language pragmas. I added them as requested by GHC when mocking the respective types. The error message seems to be the same as before.

This program yields me:

test.hs:22:17:
    Couldn't match type ‘Either String Int’ with ‘Maybe a0’
    Expected type: Either a1 [Char] -> Either String Int
      Actual type: Either a1 [Char] -> Maybe a0
    The function ‘preview’ is applied to two arguments,
    but its type ‘Getting (Data.Monoid.First a0) s0 a0
                  -> Either a1 [Char] -> Maybe a0’
    has only two
    In the second argument of ‘($)’, namely
      ‘(preview _Left (Right "abc") :: Either String Int)’
    In the expression:
      print $ (preview _Left (Right "abc") :: Either String Int)
Failed, modules loaded: none.

comment:6 Changed 5 years ago by Yuras

Status: newinfoneeded

Thank you for the test case.

That is what I get with HEAD:

test.hs:22:17:
    Couldn't match type ‘Maybe a0’ with ‘Either String Int’
    Expected type: Either a1 [Char] -> Either String Int
      Actual type: Either a1 [Char] -> Maybe a0
    The function ‘preview’ is applied to two arguments,
    its type is ‘Getting (Data.Monoid.First a0) s0 a0
                 -> m0 (Maybe a0)’,
    it is specialized to ‘Getting (Data.Monoid.First a0) s0 a0
                          -> Either a1 [Char] -> Maybe a0’
    In the second argument of ‘($)’, namely
      ‘(preview _Left (Right "abc") :: Either String Int)’
    In the expression:
      print $ (preview _Left (Right "abc") :: Either String Int)

That looks right for me, so I'd say the issue is a duplicate.

Last edited 5 years ago by Yuras (previous) (diff)

comment:7 Changed 5 years ago by thomie

Resolution: duplicate
Status: infoneededclosed

The fix for #9605 will be in 7.10.

@zardoz: please reopen if you don't think your issue is fixed in 7.10.

Note: See TracTickets for help on using tickets.