lean-ja / lean-ja/lean-by-example
structure のフィールドのデフォルト値について
Open
Nobody has claimed this yet.
宣言的コマンド
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
構造体のフィールドのデフォルト値は,Prop型ではないときは {} 記法でないと利用できない.
これは,extend したときの挙動に原因があるらしい
structure NonEmptyString where
value : String
another_value : Int := 0
ev : value.length > 0 := by decide
deriving Repr
-- works
def eg : NonEmptyString := { value := "hello" }
-- does not work
def eg' : NonEmptyString := NonEmptyString.mk "hello"
-- default value of `another_value` is missing
/-
NonEmptyString.mk (value : String) (another_value : Int) (ev : value.length > 0 := by decide) : NonEmptyString
-/
#check NonEmptyString.mk
Contributor 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.
Research direction
Start with the linked Zulip discussion and reproduce the NonEmptyString example shown in the issue. Compare the structure-literal form with the explicit NonEmptyString.mk call, then determine the cause of their different handling of default fields and document the resulting behavior or required change.
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
- Needs clarification
- Newbie friendliness
- 30/100