without-k.lagda.rst 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ..
  2. ::
  3. {-# OPTIONS --guardedness #-}
  4. module language.without-k where
  5. open import Agda.Builtin.Equality
  6. open import Agda.Builtin.Coinduction
  7. .. _without-k:
  8. *********
  9. Without K
  10. *********
  11. The option ``--without-K`` adds some restrictions to Agda's
  12. typechecking algorithm in order to ensure compatability with versions
  13. of type theory that do not support UIP (uniqueness of identity
  14. proofs), such as HoTT (homotopy type theory).
  15. The option ``--with-K`` can be used to override a global
  16. ``--without-K`` in a file, by adding a pragma
  17. ``{-# OPTIONS --with-K #-}``. This option is enabled by default.
  18. Restrictions on pattern matching
  19. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20. When the option ``--without-K`` is enabled, then Agda only accepts
  21. certain case splits. More specifically, the unification algorithm for
  22. checking case splits cannot make use of the deletion rule to solve
  23. equations of the form ``x = x``.
  24. For example, the obvious implementation of the K rule is not
  25. accepted::
  26. K : {A : Set} {x : A} (P : x ≡ x → Set) →
  27. P refl → (x≡x : x ≡ x) → P x≡x
  28. K P p refl = p
  29. Pattern matching with the constructor ``refl`` on the argument ``x≡x``
  30. causes ``x`` to be unified with ``x``, which fails because the deletion
  31. rule cannot be used when ``--without-K`` is enabled.
  32. On the other hand, the obvious implementation of the J rule is accepted::
  33. J : {A : Set} (P : (x y : A) → x ≡ y → Set) →
  34. ((x : A) → P x x refl) → (x y : A) (x≡y : x ≡ y) → P x y x≡y
  35. J P p x .x refl = p x
  36. Pattern matching with the constructor ``refl`` on the argument ``x≡y``
  37. causes ``x`` to be unified with ``y``. The same applies to Christine
  38. Paulin-Mohring's version of the J rule::
  39. J′ : {A : Set} {x : A} (P : (y : A) → x ≡ y → Set) →
  40. P x refl → (y : A) (x≡y : x ≡ y) → P y x≡y
  41. J′ P p ._ refl = p
  42. For more details, see Jesper Cockx's PhD thesis `Dependent Pattern
  43. Matching and Proof-Relevant Unification` [`Cockx (2017)
  44. <https://limo.libis.be/primo-explore/fulldisplay?docid=LIRIAS1656778&context=L&vid=Lirias>`_].
  45. Restrictions on termination checking
  46. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  47. When ``--without-K`` is enabled, Agda's termination checker restricts
  48. structural descent to arguments ending in data types or ``Size``.
  49. Likewise, guardedness is only tracked when result type is data or
  50. record type::
  51. data ⊥ : Set where
  52. mutual
  53. data WOne : Set where wrap : FOne → WOne
  54. FOne = ⊥ → WOne
  55. postulate iso : WOne ≡ FOne
  56. noo : (X : Set) → (WOne ≡ X) → X → ⊥
  57. noo .WOne refl (wrap f) = noo FOne iso f
  58. ``noo`` is rejected since at type ``X`` the structural descent
  59. ``f < wrap f`` is discounted ``--without-K``::
  60. data Pandora : Set where
  61. C : ∞ ⊥ → Pandora
  62. postulate foo : ⊥ ≡ Pandora
  63. loop : (A : Set) → A ≡ Pandora → A
  64. loop .Pandora refl = C (♯ (loop ⊥ foo))
  65. ``loop`` is rejected since guardedness is not tracked at type ``A``
  66. ``--without-K``.
  67. See issues `#1023 <https://github.com/agda/agda/issues/1023/>`_,
  68. `#1264 <https://github.com/agda/agda/issues/1264/>`_,
  69. `#1292 <https://github.com/agda/agda/issues/1292/>`_.
  70. Restrictions on universe levels
  71. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. When ``--without-K`` is enabled, some indexed datatypes must be
  73. defined in a higher universe level. In particular, the types of all
  74. indices should fit in the sort of the datatype.
  75. For example, usually (i.e. ``--with-K``) Agda allows the following
  76. definition of equality::
  77. data _≡₀_ {ℓ} {A : Set ℓ} (x : A) : A → Set where
  78. refl : x ≡₀ x
  79. However, with ``--without-K`` it must be defined at a higher
  80. universe level::
  81. data _≡′_ {ℓ} {A : Set ℓ} : A → A → Set ℓ where
  82. refl : {x : A} → x ≡′ x