lean-ja / lean-ja/lean-by-example

型クラスのダイアモンド継承があるときに、型クラス解決がうまくいかない

Open
#761 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

慣習
Dominant language
Lean
Stars
188
Forks
15
Avg merge
9h 8m
Merged PRs (30d)
6

Description

Left と Right のインスタンスがあれば Both のインスタンスも当然あってほしいが、それが上手くいかない

これは Base を両方が継承していることによる問題。回避方法はベストプラクティスとしてあったはずだが…

set_option autoImplicit false
set_option relaxedAutoImplicit false

class Base (α : Type) where
  base : α

class Left (α : Type) extends Base α where
  left : α

class Right (α : Type) extends Base α where
  right : α

class Both (α : Type) extends Left α, Right α

inductive Direction where
  | south
  | north
  | west
  | east

instance : Base Direction where
  base := Direction.south

instance : Left Direction where
  left := Direction.west

instance : Right Direction where
  right := Direction.east

/--
error: failed to synthesize
  Both Direction
Additional diagnostic information may be available using the `set_option diagnostics true` command.
-/
#check (inferInstance : Both Direction)

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

Start with the minimal Lean example in the issue and reproduce the failed inferInstance synthesis. Investigate the type-class diamond inheritance behavior and the referenced best-practice workaround. Done means the expected Both Direction resolution works, or the repository documents a verified workaround if the behavior is intentional.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.