03-classes.agda 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. {-# OPTIONS --verbose tc.constr.findInScope:15 #-}
  2. module InstanceArguments.03-classes where
  3. open import Algebra
  4. open import Data.Nat.Properties as NatProps
  5. open import Data.Nat
  6. open import Data.Bool.Properties using (∧-∨-isCommutativeSemiring)
  7. open import Data.Product using (proj₁)
  8. open import Relation.Binary.PropositionalEquality
  9. open import Relation.Binary
  10. open import Level renaming (zero to lzero; suc to lsuc)
  11. open CommutativeSemiring NatProps.*-+-commutativeSemiring using (semiring)
  12. open IsCommutativeSemiring *-+-isCommutativeSemiring using (isSemiring)
  13. open IsCommutativeSemiring ∧-∨-isCommutativeSemiring using () renaming (isSemiring to Bool-isSemiring)
  14. record S (A : Set) : Set₁ where
  15. field
  16. z : A
  17. o : A
  18. _≈_ : Rel A lzero
  19. _⟨+⟩_ : Op₂ A
  20. _⟨*⟩_ : Op₂ A
  21. instance isSemiring' : IsSemiring _≈_ _⟨+⟩_ _⟨*⟩_ z o
  22. instance
  23. ℕ-S : S ℕ
  24. ℕ-S = record { z = 0; o = 1;
  25. _≈_ = _≡_; _⟨+⟩_ = _+_; _⟨*⟩_ = _*_;
  26. isSemiring' = isSemiring }
  27. zero' : {A : Set} → {{aRing : S A}} → A
  28. zero' {{ARing}} = S.z ARing
  29. zero-nat : ℕ
  30. zero-nat = zero'
  31. isZero : {A : Set} {{r : S A}} (let open S r) →
  32. Zero _≈_ z _⟨*⟩_
  33. isZero {{r}} = IsSemiring.zero (S.isSemiring' r)
  34. useIsZero : 0 * 5 ≡ 0
  35. useIsZero = proj₁ isZero 5