diff options
| author | herbelin | 2001-12-23 12:49:18 +0000 |
|---|---|---|
| committer | herbelin | 2001-12-23 12:49:18 +0000 |
| commit | e720440da85b92f8a8b8e6c1964737340702559a (patch) | |
| tree | 0cc493de9ec4017b394f32ce75e0f9b7d1739ce5 | |
| parent | bdc2e38639bbdc06f697e6441da9f3044c71453c (diff) | |
Ajout Canonical Structure
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@8261 85f007b7-540e-0410-9357-904b9bb8a0f7
| -rw-r--r-- | doc/RefMan-ext.tex | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/doc/RefMan-ext.tex b/doc/RefMan-ext.tex index 23f6b76252..3caab62d5e 100644 --- a/doc/RefMan-ext.tex +++ b/doc/RefMan-ext.tex @@ -834,6 +834,68 @@ Check (id1 O). Print} command. \end{Warnings} +\subsection{Canonical structures} + +A canonical structure is an instance of a record/structure type that +can be used to solve equations involving implicit arguments. Assume +that {\qualid} denotes an object $(Build\_struc~ c_1~ \ldots~ c_n)$ in the +structure {\em struct} of which the fields are $x_1$, ..., +$x_n$. Assume that {\qualid} is declared as a canonical structure +using the command + +\bigskip +{\tt Canonical Structure {\qualid}.} +\comindex{Canonical Structure} +\bigskip + +Then, each time an equation of the form $(x_i~ +?)=_{\beta\delta\iota\zeta}c_i$ has to be solved during the +type-checking process, {\qualid} is used as a solution. Otherwise +said, {\qualid} is canonically used to equip the field $c_i$ into a +complete structure built on $c_i$. + +Canonical structures are particularly useful when mixed with +coercions and implicit arguments. Here is an example. + +\begin{coq_example*} +Require Relations. +Require EqNat. +Set Implicit Arguments. +Structure Setoid : Type := + {Carrier :> Set; + Equal : (relation Carrier); + Prf_equiv : (equivalence Carrier Equal)}. +Definition is_law := [A,B:Setoid][f:A->B] + (x,y:A) (Equal x y) -> (Equal (f x) (f y)). +Axiom eq_nat_equiv : (equivalence nat eq_nat). +Definition nat_setoid : Setoid := (Build_Setoid eq_nat_equiv). +Canonical Structure nat_setoid. +\end{coq_example*} + +Thanks to \texttt{nat\_setoid} declared as canonical, the implicit +arguments {\tt A} and {\tt B} can be synthesized in the next statement. + +\begin{coq_example} +Lemma is_law_S : (is_law S). +\end{coq_example} + +\Rem If a same field occurs in several canonical structure, then +only the structure declared first as canonical is considered. + +\begin{Variants} +\item {\tt Canonical Structure {\ident} := {\term} : {\type}.}\\ + {\tt Canonical Structure {\ident} := {\term}.}\\ + {\tt Canonical Structure {\ident} : {\type} := {\term}.}\\ + +These are equivalent to a regular definition of {\ident} followed by +the declaration + +{\tt Canonical Structure {\ident}}. +\end{Variants} + +\SeeAlso more examples in user contribution \texttt{category} +(\texttt{Rocq/ALGEBRA}). + \section{Implicit Coercions} \label{Coercions}\index{Coercions} |
