Inconvenient definition for NDBType.asType
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- documentation
Research direction
Start with the Typed Queries exercise and compare the conditional NDBType.asType definition with the pattern-matching alternative shown in the issue. Check the related NDBType.beq implementation and the rest of the nullable-types exercise. Done means the definition supports direct pattern-matched comparisons without the reported casts or tactic workarounds.
Written by the indexing model from the issue text.
Description
The following is given in the Typed Queries exercise
Nullable Types
Add support for nullable columns to the query language by representing database types with the following structure:
structure NDBType where
underlying : DBType
nullable : Bool
abbrev NDBType.asType (t : NDBType) : Type :=
if t.nullable then
Option t.underlying.asType
else
t.underlying.asType
Use this type in place of DBType in Column and DBExpr, and look up SQL's rules for NULL and comparison operators to determine the types of DBExpr's constructors.
It seems like Lean has issues seeing through this definition of .asType, which led to needing to use convoluted casting and tactics for the rest of the implementation.
For example, you can try to write NDBType.beq as:
def NDBType.beq (t : NDBType) (x y : t.asType) : Bool :=
match t with
| ⟨_, true⟩ => x == y
| ⟨_, false⟩ => x == y
However, Lean gives the errors:
failed to synthesize instance
BEq (asType { underlying := underlying✝, nullable := true })
failed to synthesize instance
BEq (asType { underlying := underlying✝, nullable := false })
Instead, I needed to write it as:
def NDBType.beq (t : NDBType) (x y : t.asType) : Bool :=
match t with
| ⟨t', true⟩ =>
let x' : Option t'.asType := x
x' == y
| ⟨t', false⟩ =>
let x' : t'.asType := x
x' == y
On the other hand, you can define NDBType.asType with:
abbrev NDBType.asType (t : NDBType) : Type :=
match t with
| ⟨t', true⟩ => Option t'.asType
| ⟨t', false⟩ => t'.asType
At this point, the first declaration of NDBType.beq works, as do the natural modifications needed for the rest of the exercise.
- Dominant language
- Lean
- Stars
- 211
- Forks
- 83
- Avg merge
- 8m
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from leanprover/fp-lean
-
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
leanprover/fp-lean#316 ·
-
Typo
Difficulty 1/5 Under an hour Newbie friendliness 90/100
leanprover/fp-lean#311 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
leanprover/fp-lean#304 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
leanprover/fp-lean#303 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
leanprover/fp-lean#301 · 1 comment ·
All issues in leanprover/fp-lean
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
優先度たかし
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
lean-ja/lean-by-example#2681 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
laststance/design-world#79 ·
Maintainers usually reply within 1 day
-
v2
Difficulty 1/5 Under an hour Newbie friendliness 86/100
modelcontextprotocol/python-sdk#3978 · 2 comments ·
Maintainers usually reply within 1 day