#8392 closed feature request (fixed)

Suggest AllowAmbiguousTypes

Reported by: rwbarton Owned by: simonpj
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 7.7
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: typecheck/should_fail/T8392a, typecheck/should_compile/T8392
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

The error message I get with GHC HEAD on the example program in #8390:

tf.hs:38:10:
    Could not deduce (Fun g a b0)
      arising from the ambiguity check for an instance declaration
    from the context (Fun f b c, Fun g a b)
      bound by an instance declaration:
                 (Fun f b c, Fun g a b) => Fun (Compose f g) a c
      at tf.hs:38:10-56
    The type variable ‛b0’ is ambiguous
    In the ambiguity check for:
      forall f g a c b. (Fun f b c, Fun g a b) => Fun (Compose f g) a c
    In the instance declaration for ‛Fun (Compose f g) a c’

could perhaps benefit from an appended line:

    (To defer this ambiguity check to use sites, enable AllowAmbiguousTypes)

Change History (6)

comment:1 Changed 21 months ago by monoidal

  • Owner set to monoidal

comment:2 Changed 21 months ago by simonpj

Actually I'm in the area so I can do this.

comment:3 Changed 21 months ago by monoidal

  • Owner changed from monoidal to simonpj

Simon: I'm passing to you. It's trivial to edit the error message in TcValidity.checkAmbiguity. However, this program

f :: Bool ~ Int => ()
f = ()

gives then

    Couldn't match type ‛Bool’ with ‛Int’
    Inaccessible code in the type signature for f :: Bool ~ Int => ()
    To defer this ambiguity check to use sites, enable AllowAmbiguousTypes
    In the ambiguity check for: Bool ~ Int => ()
    In the type signature for ‛f’: f :: Bool ~ Int => ()

and enabling AllowAmbiguousTypes merely changes it to

    Couldn't match type ‛Bool’ with ‛Int’
    Inaccessible code in the type signature for f :: Bool ~ Int => ()

So ambiguity check is done before checking inaccessible code, and it might be better to change this order. I don't know if this is simple or has any side effects though.

comment:4 Changed 21 months ago by Simon Peyton Jones <simonpj@…>

comment:5 Changed 21 months ago by Simon Peyton Jones <simonpj@…>

In 43856a003c9abb1bf8bf1822e6e7f5781b16ac4d/ghc:

Improve -XAllowAmbiguousTypes (Trac #8392)

* Add a suggestion to add AllowAmbiguousTypes when there is an
  ambiguity error

* Move some of the logic to tcSimplifyAmbiguityCheck

* Report inaccessible code regardless of the ambiguity check

comment:6 Changed 21 months ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to typecheck/should_fail/T8392a, typecheck/should_compile/T8392
Note: See TracTickets for help on using tickets.