positivity-checking.lagda.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. ..
  2. ::
  3. module language.positivity-checking where
  4. .. _positivity-checking:
  5. *******************
  6. Positivity Checking
  7. *******************
  8. .. note::
  9. This is a stub.
  10. .. _no_positivity_check-pragma:
  11. The ``NO_POSITIVITY_CHECK`` pragma
  12. __________________________________
  13. ..
  14. ::
  15. module no-positivity-check-pragma where
  16. The pragma switches off the positivity checker for data/record
  17. definitions and mutual blocks. This pragma was added in Agda 2.5.1
  18. The pragma must precede a data/record definition or a mutual
  19. block. The pragma cannot be used in :option:`--safe` mode.
  20. Examples:
  21. ..
  22. ::
  23. module single where
  24. * Skipping a single data definition::
  25. {-# NO_POSITIVITY_CHECK #-}
  26. data D : Set where
  27. lam : (D → D) → D
  28. * Skipping a single record definition::
  29. {-# NO_POSITIVITY_CHECK #-}
  30. record U : Set where
  31. field ap : U → U
  32. ..
  33. ::
  34. module old-style-record where
  35. * Skipping an old-style mutual block. Somewhere within a mutual block
  36. before a data/record definition::
  37. mutual
  38. data D : Set where
  39. lam : (D → D) → D
  40. {-# NO_POSITIVITY_CHECK #-}
  41. record U : Set where
  42. field ap : U → U
  43. ..
  44. ::
  45. module old-style-mutual where
  46. * Skipping an old-style mutual block. Before the ``mutual`` keyword::
  47. {-# NO_POSITIVITY_CHECK #-}
  48. mutual
  49. data D : Set where
  50. lam : (D → D) → D
  51. record U : Set where
  52. field ap : U → U
  53. ..
  54. ::
  55. module new-style-mutual where
  56. * Skipping a new-style mutual block. Anywhere before the declaration
  57. or the definition of a data/record in the block::
  58. record U : Set
  59. data D : Set
  60. record U where
  61. field ap : U → U
  62. {-# NO_POSITIVITY_CHECK #-}
  63. data D where
  64. lam : (D → D) → D
  65. .. _polarity-pragma:
  66. `POLARITY` pragmas
  67. __________________
  68. ..
  69. ::
  70. module polarity-pragmas where
  71. Polarity pragmas can be attached to postulates. The polarities express
  72. how the postulate's arguments are used. The following polarities
  73. are available:
  74. * ``_``: Unused.
  75. * ``++``: Strictly positive.
  76. * ``+``: Positive.
  77. * ``-``: Negative.
  78. * ``*``: Unknown/mixed.
  79. Polarity pragmas have the form ``{-# POLARITY name <zero or more
  80. polarities> #-}``, and can be given wherever fixity declarations can
  81. be given. The listed polarities apply to the given postulate's
  82. arguments (explicit/implicit/instance), from left to right. Polarities
  83. currently cannot be given for module parameters. If the postulate
  84. takes n arguments (excluding module parameters), then the number of
  85. polarities given must be between 0 and n (inclusive).
  86. Polarity pragmas make it possible to use postulated type formers in
  87. recursive types in the following way:
  88. ::
  89. postulate
  90. ∥_∥ : Set → Set
  91. {-# POLARITY ∥_∥ ++ #-}
  92. data D : Set where
  93. c : ∥ D ∥ → D
  94. ..
  95. ::
  96. module proof-of-bottom where
  97. Note that one can use postulates that may seem benign, together with
  98. polarity pragmas, to prove that the empty type is inhabited::
  99. postulate
  100. _⇒_ : Set → Set → Set
  101. lambda : {A B : Set} → (A → B) → A ⇒ B
  102. apply : {A B : Set} → A ⇒ B → A → B
  103. {-# POLARITY _⇒_ ++ #-}
  104. data ⊥ : Set where
  105. data D : Set where
  106. c : D ⇒ ⊥ → D
  107. not-inhabited : D → ⊥
  108. not-inhabited (c f) = apply f (c f)
  109. d : D
  110. d = c (lambda not-inhabited)
  111. bad : ⊥
  112. bad = not-inhabited d
  113. Polarity pragmas are not allowed in safe mode.