i not able understand clearly. tried learn "with" keyword there have doubt. please !!!
i wanted understand working of "with" , working of code.
something-even : ∀ n → n ⊎ (suc n) something-even 0 = inj₁ 0 something-even (suc n) something-even n ... | inj₁ x = inj₂ (suc-suc x) ... | inj₂ y = inj₁ y (this states either n or successor even). in fact, thm0 can implemented without using recursion! thm0 : ∀ x → ∃ λ y → y × x less-than y thm0 n something-even n ... | inj₁ x = suc (suc n) , suc-suc x , suc ref ... | inj₂ y = suc n , y , ref
if familiar haskell, notice in agda there no if
-statements , no case
.
with
pattern-matching of expression result. example, with something-even n
evaluates something-even n
, , pattern-matches on following lines ... | inj₁ x
, ... | inj₂ y
. these match expression, see if value constructed using inj₁
or inj₂
constructor, value wrapped them can used in right-hand-side expressions: suc (suc n) , suc-suc x , suc ref
uses x
determined inj₁ x
, , suc n , y , ref
uses y
determined inj₂ y
the actual constructor names come definition of ⊎
- see type of something-even
joins types even n
, even (suc n)
. x
in inj₁ x
corresponds value of type even n
given n
, , y
in inj₂ y
corresponds value of type even (suc n)
same n
.
Comments
Post a Comment