| 1 | # Notes on SProp |
| 2 | |
| 3 | (ml API side, see refman for user side) |
| 4 | |
| 5 | ## Relevance |
| 6 | |
| 7 | All kernel binders (`Prod`/`Lambda`/`LetIn`/`Context` elements) are |
| 8 | now annotated with a value in `type Sorts.relevance = Relevant | |
| 9 | Irrelevant`. It should verify that the binder's type lives in `SProp` |
| 10 | iff the annotation is `Irrelevant`. |
| 11 | |
| 12 | As a plugin you can generally just use `Relevant` everywhere, the |
| 13 | kernel will fix it if needed when it checks the terms you produce. The |
| 14 | only issue is that if you generate `Relevant` when it should have been |
| 15 | `Irrelevant` you won't be able to use proof irrelevance on that |
| 16 | variable until the kernel fixes it. See refman for examples as Rocq |
| 17 | also uses `Relevant` incorrectly in some places. |
| 18 | |
| 19 | This annotation is done by transforming the binder name `'a` into a |
| 20 | `'a Context.binder_annot = { binder_name : 'a; binder_relevance : |
| 21 | Sorts.relevance }`, eg `Prod of Name.t * types * types` becomes `Prod |
| 22 | of Name.t Context.binder_annot * types * types`. |
| 23 | |
| 24 | If you just carry binder names around without looking at them no |
| 25 | change is needed, eg if you have `match foo with Lambda (x, a, b) -> |
| 26 | Prod (x, a, type_of (push_rel (LocalAssum (x,a)) env) b)`. Otherwise |
| 27 | see `context.mli` for a few combinators on the `binder_annot` type. |
| 28 | |
| 29 | When making `Relevant` annotations you can use some convenience |
| 30 | functions from `Context` (eg `annotR x = make_annot x Relevant`), also |
| 31 | `mkArrowR` from `Constr`/`EConstr` which has the signature of the old |
| 32 | `mkArrow`. |
| 33 | |
| 34 | Relevance can be inferred from a well-typed term using functions in |
| 35 | `Retypeops` (for `Constr`) and `Retyping` (for `EConstr`). For `x` a |
| 36 | term, note the difference between its relevance as a term (is `x : |
| 37 | (_ : SProp)`) and as a type (is `x : SProp`), there are functions for |
| 38 | both kinds. |
| 39 | |
| 40 | ## Case inversion |
| 41 | |
| 42 | Inductives in SProp with 1 constructor which has no arguments have a |
| 43 | special reduction rule for matches. To implement it the Case |
| 44 | constructor is extended with a `case_invert` field. |
| 45 | |
| 46 | If you are constructing a match on a normal (non-special reduction) |
| 47 | inductive you must fill the new field with `NoInvert`. Otherwise you |
| 48 | must fill it with `CaseInvert {univs ; args}` where `univs` is the |
| 49 | universe instance of the type you are matching and `args` the |
| 50 | parameters and indices. |
| 51 | |
| 52 | For instance, in |
| 53 | |
| 54 | ~~~coq |
| 55 | Inductive seq {A} (a:A) : A -> SProp := |
| 56 | srefl : seq a a. |
| 57 | |
| 58 | Definition seq_to_eq {A x y} (e:seq x y) : x = y :> A |
| 59 | := match e with srefl => eq_refl end. |
| 60 | ~~~ |
| 61 | |
| 62 | the `match e with ...` has `CaseInvert {univs = Instance.empty; args = [|A x y|]}`. |
| 63 | (empty instance since we defined a universe monomorphic `seq`). |
| 64 | |
| 65 | In practice, you should use `Inductiveops.make_case_or_project` which |
| 66 | will take care of this for you (and also handles primitive records |
| 67 | correctly etc). |