haskell / haskell/error-messages

Mention existential type variables in 'relevant bindings'

Open
#550 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
76
Forks
19
PR merge metrics
No merged PRs in 30d

Description

For this example code --

```haskell
{-# LANGUAGE GADTs #-}

data T where
X :: T
Y :: a -> T

f :: T -> ()
f X = ()
f (Y a) = _
```

The error message (`ghc 9.0.2`) reads -

```
example.hs:9:11: error:
• Found hole: _ :: ()
• In the expression: _
In an equation for ‘f’: f (Y a) = _
• Relevant bindings include
a :: a (bound at example.hs:9:6)
f :: T -> () (bound at example.hs:8:1)
Valid hole fits include
.....
```

The type of `a` is just `a`. Would it be possible for GHC to do something like this? -

```
• Relevant bindings include
a :: a (bound at example.hs:9:6)
f :: T -> () (bound at example.hs:8:1)
• Where <------
a is an existential type variable <------
```

Additionally, would it be possible to annotate `a` with the location where it is introduced (so, for the above example, it could read `a is an existential type variable introduced at example.hs:5:9`) and any constraints on it? I believe the error messages for escaping skolem variables already do something similar -

```
data Any where
Any :: a -> Any

Any True :: Any
Any (show :: Int -> String) :: Any

f (Any a) = a
```

```
• Couldn't match expected type ‘t’ with actual type ‘a’ because type variable ‘a’ would escape its scope
This (rigid, skolem) type variable is bound by a pattern with constructor: Any :: forall a. a -> Any,
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.