-
Notifications
You must be signed in to change notification settings - Fork 54
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.