leanprover / leanprover/lean4

Confusing error message for type class resolution failures

Open
#2,847 4 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

new-user-papercuts P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Description

New users who work in Lean may reasonably write:

def add1 x := x + 1

which is accepted due to the default instance for OfNat 1 Nat.

But if they then also reasonably write

def times x y := x * y

they get this message:

typeclass instance problem is stuck, it is often due to metavariables
  HMul ?m.5498 (?m.5486 x) (?m.5487 x y)

This is not particularly actionable, and it's quite intimidating (what's a metavariable? what's a type class? What's that big number next to the question mark for? What in the world is HMul?). In classroom settings, failures to find Num instances is a common source of difficulty for students learning Haskell, so there is good reason to think that this will be an issue for Lean learners too.

Versions

Lean (version 4.3.0, commit 734ce1ef2f62, Release)

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the two Lean definitions from the issue and inspect where the typeclass-resolution failure is reported. The work is done when the failure is communicated in an actionable way for new Lean users without the current intimidating metavariable and HMul details.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.