Skip to content

Report required constraints when reporting the type of a hole

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.

Trac metadata
Trac field Value
Version 7.8.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority low
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information