I found out that plus
function for Nat
s is implemented in this way
total plus : (n, m : Nat) -> Nat
plus Z right = right
plus (S left) right = S (plus left right)
I wonder if there is particular reason not to pattern match on the second argument as well like here:
total plus : (n, m : Nat) -> Nat
plus Z right = right
plus left Z = left
plus (S left) right = S (plus left right)
As I see for the moment this implementation would make life simpler in many proofs and code. For example
total plusZeroRightNeutral : (left : Nat) -> left + 0 = left
plusZeroRightNeutral Z = Refl
plusZeroRightNeutral (S n) =
let inductiveHypothesis = plusZeroRightNeutral n in
rewrite inductiveHypothesis in Refl
would look like plusZeroLeftNeutral
:
total plusZeroRightNeutral : (left : Nat) -> left + 0 = left
plusZeroRightNeutral left = Refl
In real life we don't even need to use plusZeroLeftNeutral
theorem because Idris can do pattern matching automatically (as it already mentioned in the answer to this question: Concatenation of two vectors - why are lengths not treated as commutative? ).
So why not add extra cases to make life easier?