leanprover / leanprover/fp-lean
Section 5.4: Wrong simplification for checkCompany
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 192
- Forks
- 73
- PR merge metrics
- No merged PRs in 30d
Description
Please quote the text that is incorrect:
One more simplification is possible. For every Applicative, pure f <*> E is equivalent to f <$> E. In other words, using seq to apply a function that was placed into the Applicative type using pure is overkill, and the function could have just been applied using Functor.map. This simplification yields:
def checkCompany (input : RawInput) :
Validate (Field × String) LegacyCheckedInput :=
checkThat (input.birthYear == "FIRM")
"birth year" "FIRM if a company" *>
.company <$> checkName input.name
In what way is this incorrect?
This simplification is technically incorrect, because:
The second definition of checkCompany yields to the following expansion:
Seq.seq
(SeqRight.seqRight (checkThat (BEq.beq myInput.birthYear "FIRM") "birth year" "FIRM is a company") fun x ↦
pure LegacyCheckedInput.company)
fun x ↦ checkName myInput.name : Validate (Prod Field String) LegacyCheckedInput
and the third one using map yields to:
SeqRight.seqRight (checkThat (BEq.beq myInput.birthYear "FIRM") "birth year" "FIRM is a company") fun x ↦
Functor.map LegacyCheckedInput.company (checkName myInput.name) : Validate (Prod Field String) LegacyCheckedInput
Proposed Correction
Add necessary parenthesis to the second checkCompany implementation:
def checkCompany (input : RawInput) : Validate (Field × String) LegacyCheckedInput :=
checkThat (input.birthYear == "FIRM") "birth year" "FIRM is a company" *>
(pure .company <*> checkName input.name)
this yields to the following expansion:
SeqRight.seqRight (checkThat (BEq.beq myInput.birthYear "FIRM") "birth year" "FIRM is a company") fun x ↦
Seq.seq (pure LegacyCheckedInput.company) fun x ↦
checkName myInput.name : Validate (Prod Field String) LegacyCheckedInput
which is consistent tho the third implementation.
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
Review Section 5.4 and locate the quoted checkCompany examples in the documentation. Compare the second implementation with the stated Applicative simplification and the expansion shown in the issue; update the example with the necessary parentheses so it is consistent with the third implementation.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100