Opened 8 months ago

Last modified 6 weeks ago

#9479 new feature request

Report required constraints when reporting the type of a hole

Reported by: dominiquedevriese Owned by:
Priority: low Milestone:
Component: Compiler (Type checker) Version: 7.8.3
Keywords: holes Cc: ekmett
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

For the following code

module Test where

test :: String
test = show _h

GHC currently reports:

Found hole ‘_h’ with type: a0
Where: ‘a0’ is an ambiguous type variable
Relevant bindings include
  test :: String (bound at /tmp/Test.hs:4:1)
In the first argument of ‘show’, namely ‘_h’
In the expression: show _h
In an equation for ‘test’: test = show _h

It correctly does not report the lack of a Show _a instance as a separate type error. However, it would be useful if the report containing the type of the hole would also contain the constraints that apply to its type. Something like:

Found hole ‘_h’ with type: a0
Where: ‘a0’ is an ambiguous type variable
Applicable constraints: Show a0
Relevant bindings include
  test :: String (bound at /tmp/Test.hs:4:1)
In the first argument of ‘show’, namely ‘_h’
In the expression: show _h
In an equation for ‘test’: test = show _h

I am explicitly *not* suggesting to report a type like Show a0 => a0 for the hole, because that might mistakenly suggest that we are looking for a value of type forall a0. Show a0 => a0, which we are not. A possible alternative is to use an imaginary exists type like exists a0. Show a0 => a0 but that's probably just even more confusing.

Change History (6)

comment:1 Changed 8 months ago by dominiquedevriese

comment:2 Changed 8 months ago by mentheta

How can I watch this ticket for activity? I am interested in future development related to this feature.

I'm sorry if this "meta question" is out of place, but I couldn't find a "watch button" either on this page, or for trac in general.

comment:3 Changed 8 months ago by goldfire

Open up the "Modify Ticket" option near the comment box and add your email to the "Cc" field.

comment:4 Changed 7 months ago by simonpj

I think this would be fairly easy to implement, and I talked to someone at ICFP who plans to do so. Happy to offer guidance.

Simon

comment:5 Changed 4 months ago by phadej

With -fdefer-type-errors GHC (both 7.8 and 7.10) tries a bit longer and finds the missing instance:

[1 of 1] Compiling Test             ( /Users/ogre/show.hs, /Users/ogre/show.o )

/Users/ogre/show.hs:4:8: Warning:
    No instance for (Show a0) arising from a use of ‘show’
    The type variable ‘a0’ is ambiguous
    Note: there are several potential instances:
      instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
      instance Show Ordering -- Defined in ‘GHC.Show’
      instance Show Integer -- Defined in ‘GHC.Show’
      ...plus 22 others
    In the expression: show _h
    In an equation for ‘test’: test = show _h

/Users/ogre/show.hs:4:13: Warning:
    Found hole ‘_h’
      with type: a0
    Where: ‘a0’ is an ambiguous type variable
    Relevant bindings include
      test :: String (bound at /Users/ogre/show.hs:4:1)
    In the first argument of ‘show’, namely ‘_h’
    In the expression: show _h
    In an equation for ‘test’: test = show _h

So should we make holeReporter to try to find Dicts errors too, if -fdefer-type-errors is not set? IMHO the No instance error is what we need here.

comment:6 Changed 6 weeks ago by ekmett

  • Cc ekmett added
Note: See TracTickets for help on using tickets.