flat.lagda.rst 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ..
  2. ::
  3. module language.flat where
  4. open import Agda.Primitive
  5. open import Agda.Builtin.Equality
  6. variable
  7. A : Set
  8. B : Set
  9. P : A -> Set
  10. .. _flat:
  11. *************
  12. Flat Modality
  13. *************
  14. The flat/crisp attribute ``@♭/@flat`` is an idempotent comonadic
  15. modality modeled after `Spatial Type Theory
  16. <https://arxiv.org/abs/1509.07584/>`_ and `Crisp Type Theory
  17. <https://arxiv.org/abs/1801.07664/>`_. It is similar to a necessity modality.
  18. We can define ``♭ A`` as a type for any ``(@♭ A : Set l)`` via an
  19. inductive definition:
  20. ::
  21. data ♭ {@♭ l : Level} (@♭ A : Set l) : Set l where
  22. con : (@♭ x : A) → ♭ A
  23. counit : {@♭ l : Level} {@♭ A : Set l} → ♭ A → A
  24. counit (con x) = x
  25. When trying to provide a ``@♭`` arguments only other ``@♭``
  26. variables will be available, the others will be marked as ``@⊤`` in the context.
  27. For example the following will not typecheck:
  28. .. code-block:: agda
  29. unit : {@♭ l : Level} {@♭ A : Set l} → A → ♭ A
  30. unit x = con x
  31. .. _pattern-matching-on-flat:
  32. Pattern Matching on ``@♭``
  33. ----------------------------
  34. Agda allows matching on ``@♭`` arguments by default.
  35. When matching on a ``@♭`` argument the flat
  36. status gets propagated to the arguments of the constructor
  37. ::
  38. data _⊎_ (A B : Set) : Set where
  39. inl : A → A ⊎ B
  40. inr : B → A ⊎ B
  41. flat-sum : {@♭ A B : Set} → (@♭ x : A ⊎ B) → ♭ A ⊎ ♭ B
  42. flat-sum (inl x) = inl (con x)
  43. flat-sum (inr x) = inr (con x)
  44. When refining ``@♭`` variables the equality also needs to be
  45. provided as ``@♭``
  46. ::
  47. flat-subst : {@♭ A : Set} {P : A → Set} (@♭ x y : A) (@♭ eq : x ≡ y) → P x → P y
  48. flat-subst x .x refl p = p
  49. if we simply had ``(eq : x ≡ y)`` the code would be rejected.
  50. Pattern matching on ``@♭`` arguments can be disabled entirely by using
  51. the ``--no-flat-split`` flag
  52. .. code-block:: agda
  53. {-# OPTIONS --no-flat-split #-}