~ubuntu-branches/ubuntu/wily/coq-doc/wily

« back to all changes in this revision

Viewing changes to doc/refman/Coercion.tex

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu, Stéphane Glondu, Samuel Mimram
  • Date: 2010-01-07 22:50:39 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100107225039-n3cq82589u0qt0s2
Tags: 8.2pl1-1
[ Stéphane Glondu ]
* New upstream release (Closes: #563669)
  - remove patches
* Packaging overhaul:
  - use git, advertise it in Vcs-* fields of debian/control
  - use debhelper 7 and dh with override
  - use source format 3.0 (quilt)
* debian/control:
  - set Maintainer to d-o-m, set Uploaders to Sam and myself
  - add Homepage field
  - bump Standards-Version to 3.8.3
* Register PDF documentation into doc-base
* Add debian/watch
* Update debian/copyright

[ Samuel Mimram ]
* Change coq-doc's description to mention that it provides documentation in
  pdf format, not postscript, closes: #543545.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
\achapter{Implicit Coercions}
 
2
\aauthor{Amokrane Sa�bi}
 
3
 
 
4
\label{Coercions-full}
 
5
\index{Coercions!presentation}
 
6
 
 
7
\asection{General Presentation}
 
8
 
 
9
This section describes the inheritance mechanism of {\Coq}. In {\Coq} with
 
10
inheritance, we are not interested in adding any expressive power to
 
11
our theory, but only convenience. Given a term, possibly not typable,
 
12
we are interested in the problem of determining if it can be well
 
13
typed modulo insertion of appropriate coercions.  We allow to write:
 
14
 
 
15
\begin{itemize}
 
16
\item $f~a$ where $f:forall~ x:A, B$ and $a:A'$ when $A'$ can 
 
17
      be seen in some sense as a subtype of $A$.
 
18
\item $x:A$ when $A$ is not a type, but can be seen in 
 
19
      a certain sense as a type: set, group, category etc.
 
20
\item $f~a$ when $f$ is not a function, but can be seen in a certain sense
 
21
      as a function: bijection, functor, any structure morphism etc.
 
22
\end{itemize}
 
23
 
 
24
\asection{Classes}
 
25
\index{Coercions!classes}
 
26
 A class with $n$ parameters is any defined name with a type
 
27
$forall~ (x_1:A_1)..(x_n:A_n), s$ where $s$ is a sort.  Thus a class with
 
28
parameters is considered as a single class and not as a family of
 
29
classes.  An object of a class $C$ is any term of type $C~t_1
 
30
.. t_n$.  In addition to these user-classes, we have two abstract
 
31
classes:
 
32
 
 
33
\begin{itemize}
 
34
\item {\tt Sortclass}, the class of sorts; 
 
35
  its objects are the terms whose type is a sort.
 
36
\item {\tt Funclass}, the class of functions; 
 
37
  its objects are all the terms with a functional 
 
38
  type, i.e. of form $forall~ x:A, B$.
 
39
\end{itemize}
 
40
 
 
41
Formally, the syntax of a classes is defined on Figure~\ref{fig:classes}.
 
42
\begin{figure}
 
43
\begin{centerframe}
 
44
\begin{tabular}{lcl}
 
45
{\class} & ::= & {\qualid} \\
 
46
  & $|$ & {\tt Sortclass} \\
 
47
  & $|$ & {\tt Funclass} 
 
48
\end{tabular}
 
49
\end{centerframe}
 
50
\caption{Syntax of classes}
 
51
\label{fig:classes}
 
52
\end{figure}
 
53
 
 
54
\asection{Coercions}
 
55
\index{Coercions!Funclass}
 
56
\index{Coercions!Sortclass}
 
57
  A name $f$ can be declared as a coercion between a source user-class
 
58
$C$ with $n$ parameters and a target class $D$ if one of these
 
59
conditions holds:
 
60
 
 
61
\newcommand{\oftype}{\!:\!}
 
62
 
 
63
\begin{itemize}
 
64
\item $D$ is a user-class, then the type of $f$ must have the form
 
65
      $forall~ (x_1 \oftype A_1)..(x_n \oftype A_n)(y\oftype C~x_1..x_n), D~u_1..u_m$ where $m$
 
66
      is the number of parameters of $D$.
 
67
\item $D$ is {\tt Funclass}, then the type of $f$ must have the form
 
68
      $forall~ (x_1\oftype A_1)..(x_n\oftype A_n)(y\oftype C~x_1..x_n)(x:A), B$. 
 
69
\item $D$ is {\tt Sortclass}, then the type of $f$ must have the form
 
70
      $forall~ (x_1\oftype A_1)..(x_n\oftype A_n)(y\oftype C~x_1..x_n), s$ with $s$ a sort. 
 
71
\end{itemize}
 
72
 
 
73
We then write $f:C \mbox{\texttt{>->}} D$. The restriction on the type
 
74
of coercions is called {\em the uniform inheritance condition}.
 
75
Remark that the abstract classes {\tt Funclass} and {\tt Sortclass}
 
76
cannot be source classes.
 
77
 
 
78
To coerce an object $t:C~t_1..t_n$ of $C$ towards $D$, we have to
 
79
apply the coercion $f$ to it; the obtained term $f~t_1..t_n~t$ is
 
80
then an object of $D$.
 
81
 
 
82
\asection{Identity Coercions}
 
83
\index{Coercions!identity}
 
84
 
 
85
  Identity coercions are special cases of coercions used to go around
 
86
the uniform inheritance condition.  Let $C$ and $D$ be two classes
 
87
with respectively $n$ and $m$ parameters and
 
88
$f:forall~(x_1:T_1)..(x_k:T_k)(y:C~u_1..u_n), D~v_1..v_m$ a function which
 
89
does not verify the uniform inheritance condition. To declare $f$ as
 
90
coercion, one has first to declare a subclass $C'$ of $C$:
 
91
 
 
92
$$C' := fun~ (x_1:T_1)..(x_k:T_k) => C~u_1..u_n$$
 
93
 
 
94
\noindent We then define an {\em identity coercion} between $C'$ and $C$:
 
95
\begin{eqnarray*}
 
96
Id\_C'\_C  & := & fun~ (x_1:T_1)..(x_k:T_k)(y:C'~x_1..x_k) => (y:C~u_1..u_n)\\
 
97
\end{eqnarray*}
 
98
 
 
99
We can now declare $f$ as coercion from $C'$ to $D$, since we can
 
100
``cast'' its type as
 
101
$forall~ (x_1:T_1)..(x_k:T_k)(y:C'~x_1..x_k),D~v_1..v_m$.\\ The identity
 
102
coercions have a special status: to coerce an object $t:C'~t_1..t_k$
 
103
of $C'$ towards $C$, we does not have to insert explicitly $Id\_C'\_C$
 
104
since $Id\_C'\_C~t_1..t_k~t$ is convertible with $t$.  However we
 
105
``rewrite'' the type of $t$ to become an object of $C$; in this case,
 
106
it becomes $C~u_1^*..u_k^*$ where each $u_i^*$ is the result of the
 
107
substitution in $u_i$ of the variables $x_j$ by $t_j$.
 
108
 
 
109
 
 
110
\asection{Inheritance Graph}
 
111
\index{Coercions!inheritance graph}
 
112
Coercions form an inheritance graph with classes as nodes.  We call
 
113
{\em coercion path} an ordered list of coercions between two nodes of
 
114
the graph.  A class $C$ is said to be a subclass of $D$ if there is a
 
115
coercion path in the graph from $C$ to $D$; we also say that $C$
 
116
inherits from $D$. Our mechanism supports multiple inheritance since a
 
117
class may inherit from several classes, contrary to simple inheritance
 
118
where a class inherits from at most one class.  However there must be
 
119
at most one path between two classes.  If this is not the case, only
 
120
the {\em oldest} one is valid and the others are ignored. So the order
 
121
of declaration of coercions is important.
 
122
 
 
123
We extend notations for coercions to coercion paths. For instance
 
124
$[f_1;..;f_k]:C \mbox{\texttt{>->}} D$ is the coercion path composed
 
125
by the coercions $f_1..f_k$.  The application of a coercion path to a
 
126
term consists of the successive application of its coercions.
 
127
 
 
128
\asection{Declaration of Coercions}
 
129
 
 
130
%%%%% "Class" is useless, since classes are implicitely defined via coercions.
 
131
 
 
132
% \asubsection{\tt Class {\qualid}.}\comindex{Class}
 
133
% Declares {\qualid} as a new class.
 
134
 
 
135
% \begin{ErrMsgs}
 
136
% \item {\qualid} \errindex{not declared}
 
137
% \item {\qualid} \errindex{is already a class}
 
138
% \item \errindex{Type of {\qualid} does not end with a sort}
 
139
% \end{ErrMsgs}
 
140
 
 
141
% \begin{Variant}
 
142
% \item {\tt Class Local {\qualid}.} \\
 
143
% Declares the construction denoted by {\qualid} as a new local class to 
 
144
% the current section.
 
145
% \end{Variant}
 
146
 
 
147
% END "Class" is useless
 
148
 
 
149
\asubsection{\tt Coercion {\qualid} : {\class$_1$} >-> {\class$_2$}.}
 
150
\comindex{Coercion}
 
151
 
 
152
Declares the construction denoted by {\qualid} as a coercion between
 
153
{\class$_1$} and {\class$_2$}.
 
154
 
 
155
% Useless information
 
156
% The classes {\class$_1$} and {\class$_2$} are first declared if necessary.
 
157
   
 
158
\begin{ErrMsgs}
 
159
\item {\qualid} \errindex{not declared}
 
160
\item {\qualid} \errindex{is already a coercion}
 
161
\item \errindex{Funclass cannot be a source class}
 
162
\item \errindex{Sortclass cannot be a source class}
 
163
\item {\qualid} \errindex{is not a function}
 
164
\item \errindex{Cannot find the source class of {\qualid}}
 
165
\item \errindex{Cannot recognize {\class$_1$} as a source class of {\qualid}}
 
166
\item {\qualid} \errindex{does not respect the inheritance uniform condition}
 
167
\item \errindex{Found target class {\class} instead of {\class$_2$}}
 
168
 
 
169
\end{ErrMsgs}
 
170
 
 
171
When the coercion {\qualid} is added to the inheritance graph, non
 
172
valid coercion paths are ignored; they are signaled by a warning.
 
173
\\[0.3cm]
 
174
\noindent {\bf Warning :}
 
175
\begin{enumerate}
 
176
\item \begin{tabbing}
 
177
{\tt Ambiguous paths: }\= $[f_1^1;..;f_{n_1}^1] : C_1\mbox{\tt >->}D_1$\\
 
178
                       \> ... \\
 
179
                       \>$[f_1^m;..;f_{n_m}^m] : C_m\mbox{\tt >->}D_m$
 
180
      \end{tabbing}
 
181
\end{enumerate}
 
182
 
 
183
\begin{Variants}
 
184
\item {\tt Local Coercion {\qualid} : {\class$_1$} >-> {\class$_2$}.}
 
185
\comindex{Local Coercion}\\
 
186
  Declares the construction denoted by {\qualid} as a coercion local to
 
187
  the current section.
 
188
 
 
189
\item {\tt Coercion {\ident} := {\term}}\comindex{Coercion}\\
 
190
  This defines {\ident} just like \texttt{Definition {\ident} :=
 
191
    {\term}}, and then declares {\ident} as a coercion between it
 
192
  source and its target.
 
193
 
 
194
\item {\tt Coercion {\ident} := {\term} : {\type}}\\
 
195
  This defines {\ident} just like 
 
196
  \texttt{Definition {\ident} : {\type} := {\term}}, and then
 
197
  declares {\ident} as a coercion between it source and its target. 
 
198
 
 
199
\item {\tt Local Coercion {\ident} := {\term}}\comindex{Local Coercion}\\
 
200
  This defines {\ident} just like \texttt{Let {\ident} :=
 
201
    {\term}}, and then declares {\ident} as a coercion between it
 
202
  source and its target.
 
203
 
 
204
\item Assumptions can be declared as coercions at declaration
 
205
time. This extends the grammar of declarations from Figure
 
206
\ref{sentences-syntax} as follows:
 
207
\comindex{Variable \mbox{\rm (and coercions)}}
 
208
\comindex{Axiom \mbox{\rm (and coercions)}}
 
209
\comindex{Parameter \mbox{\rm (and coercions)}}
 
210
\comindex{Hypothesis \mbox{\rm (and coercions)}}
 
211
 
 
212
\begin{tabular}{lcl}
 
213
%% Declarations
 
214
{\declaration} & ::= & {\declarationkeyword} {\assums} {\tt .} \\
 
215
&&\\
 
216
{\assums} & ::= & {\simpleassums} \\
 
217
          & $|$ & \nelist{{\tt (} \simpleassums {\tt )}}{} \\
 
218
&&\\
 
219
{\simpleassums} & ::= &  \nelist{\ident}{} {\tt :}\zeroone{{\tt >}} {\term}\\  
 
220
\end{tabular}
 
221
 
 
222
If the extra {\tt >} is present before the type of some assumptions, these
 
223
assumptions are declared as coercions.
 
224
 
 
225
\item Constructors of inductive types can be declared as coercions at
 
226
definition time of the inductive type. This extends and modifies the
 
227
grammar of inductive types from Figure \ref{sentences-syntax} as follows: 
 
228
\comindex{Inductive \mbox{\rm (and coercions)}}
 
229
\comindex{CoInductive \mbox{\rm (and coercions)}}
 
230
 
 
231
\begin{center}
 
232
\begin{tabular}{lcl}
 
233
%% Inductives
 
234
{\inductive} & ::= & 
 
235
           {\tt Inductive} \nelist{\inductivebody}{with} {\tt .} \\
 
236
 & $|$ & {\tt CoInductive} \nelist{\inductivebody}{with} {\tt .} \\
 
237
           & & \\
 
238
{\inductivebody} & ::= & 
 
239
  {\ident} \sequence{\binderlet}{} {\tt :} {\term} {\tt :=} \\
 
240
   && ~~~\zeroone{\zeroone{\tt |} \nelist{\constructor}{|}} \\
 
241
           & & \\
 
242
{\constructor} & ::= &  {\ident} \sequence{\binderlet}{} \zeroone{{\tt :}\zeroone{\tt >} {\term}} \\
 
243
\end{tabular}
 
244
\end{center}
 
245
 
 
246
Especially, if the extra {\tt >} is present in a constructor
 
247
declaration, this constructor is declared as a coercion.
 
248
\end{Variants}
 
249
 
 
250
\asubsection{\tt Identity Coercion {\ident}:{\class$_1$} >-> {\class$_2$}.} 
 
251
\comindex{Identity Coercion}
 
252
 
 
253
We check that {\class$_1$} is a constant with a value of the form
 
254
$fun~ (x_1:T_1)..(x_n:T_n) => (\mbox{\class}_2~t_1..t_m)$ where $m$ is the
 
255
number of parameters of \class$_2$.  Then we define an identity
 
256
function with the type
 
257
$forall~ (x_1:T_1)..(x_n:T_n)(y:\mbox{\class}_1~x_1..x_n),
 
258
{\mbox{\class}_2}~t_1..t_m$, and we declare it as an identity
 
259
coercion between {\class$_1$} and {\class$_2$}.
 
260
 
 
261
\begin{ErrMsgs}
 
262
\item {\class$_1$} \errindex{must be a transparent constant} 
 
263
\end{ErrMsgs}
 
264
 
 
265
\begin{Variants}
 
266
\item {\tt Local Identity Coercion {\ident}:{\ident$_1$} >-> {\ident$_2$}.} \\
 
267
Idem but locally to the current section.
 
268
 
 
269
\item {\tt SubClass {\ident} := {\type}.} \\
 
270
\comindex{SubClass}
 
271
 If {\type} is a class
 
272
{\ident'} applied to some arguments then {\ident} is defined and an
 
273
identity coercion of name {\tt Id\_{\ident}\_{\ident'}} is
 
274
declared. Otherwise said, this is an abbreviation for 
 
275
 
 
276
{\tt Definition {\ident} := {\type}.} 
 
277
 
 
278
 followed by
 
279
 
 
280
{\tt Identity Coercion Id\_{\ident}\_{\ident'}:{\ident} >-> {\ident'}}.
 
281
 
 
282
\item {\tt Local SubClass {\ident} := {\type}.} \\
 
283
Same as before but locally to the current section.
 
284
 
 
285
\end{Variants}
 
286
 
 
287
\asection{Displaying Available Coercions}
 
288
 
 
289
\asubsection{\tt Print Classes.} 
 
290
\comindex{Print Classes}
 
291
Print the list of declared classes in the current context.
 
292
 
 
293
\asubsection{\tt Print Coercions.}
 
294
\comindex{Print Coercions}
 
295
Print the list of declared coercions in the current context.
 
296
 
 
297
\asubsection{\tt Print Graph.} 
 
298
\comindex{Print Graph}
 
299
Print the list of valid coercion paths in the current context.
 
300
 
 
301
\asubsection{\tt Print Coercion Paths {\class$_1$} {\class$_2$}.} 
 
302
\comindex{Print Coercion Paths}
 
303
Print the list of valid coercion paths from {\class$_1$} to {\class$_2$}.
 
304
 
 
305
\asection{Activating the Printing of Coercions}
 
306
 
 
307
\asubsection{\tt Set Printing Coercions.}
 
308
\comindex{Set Printing Coercions}
 
309
\comindex{Unset Printing Coercions}
 
310
 
 
311
This command forces all the coercions to be printed.
 
312
Conversely, to skip the printing of coercions, use
 
313
 {\tt Unset Printing Coercions}.
 
314
By default, coercions are not printed.
 
315
 
 
316
\asubsection{\tt Set Printing Coercion {\qualid}.}
 
317
\comindex{Set Printing Coercion}
 
318
\comindex{Unset Printing Coercion}
 
319
 
 
320
This command forces coercion denoted by {\qualid} to be printed.
 
321
To skip the printing of coercion {\qualid}, use
 
322
 {\tt Unset Printing Coercion {\qualid}}.
 
323
By default, a coercion is never printed.
 
324
 
 
325
\asection{Classes as Records}
 
326
\label{Coercions-and-records}
 
327
\index{Coercions!and records}
 
328
We allow the definition of {\em Structures with Inheritance} (or
 
329
classes as records) by extending the existing {\tt Record} macro
 
330
(see Section~\ref{Record}). Its new syntax is:
 
331
 
 
332
\begin{center}
 
333
\begin{tabular}{l}
 
334
{\tt Record \zeroone{>}~{\ident} {\binderlet} : {\sort} := \zeroone{\ident$_0$} \verb+{+} \\
 
335
~~~~\begin{tabular}{l}
 
336
        {\tt \ident$_1$ $[$:$|$:>$]$ \term$_1$ ;} \\
 
337
        ... \\
 
338
        {\tt \ident$_n$ $[$:$|$:>$]$ \term$_n$ \verb+}+. }
 
339
    \end{tabular}
 
340
\end{tabular}
 
341
\end{center}
 
342
The identifier {\ident} is the name of the defined record and {\sort}
 
343
is its type. The identifier {\ident$_0$} is the name of its
 
344
constructor. The identifiers {\ident$_1$}, .., {\ident$_n$} are the
 
345
names of its fields and {\term$_1$}, .., {\term$_n$} their respective
 
346
types. The alternative {\tt $[$:$|$:>$]$} is ``{\tt :}'' or ``{\tt
 
347
:>}''. If {\tt {\ident$_i$}:>{\term$_i$}}, then {\ident$_i$} is
 
348
automatically declared as coercion from {\ident} to the class of
 
349
{\term$_i$}.  Remark that {\ident$_i$} always verifies the uniform
 
350
inheritance condition.  If the optional ``{\tt >}'' before {\ident} is
 
351
present, then {\ident$_0$} (or the default name {\tt Build\_{\ident}}
 
352
if {\ident$_0$} is omitted) is automatically declared as a coercion
 
353
from the class of {\term$_n$} to {\ident} (this may fail if the
 
354
uniform inheritance condition is not satisfied).
 
355
 
 
356
\Rem The keyword {\tt Structure}\comindex{Structure} is a synonym of {\tt
 
357
Record}.
 
358
 
 
359
\asection{Coercions and Sections}
 
360
\index{Coercions!and sections}
 
361
  The inheritance mechanism is compatible with the section
 
362
mechanism. The global classes and coercions defined inside a section
 
363
are redefined after its closing, using their new value and new
 
364
type. The classes and coercions which are local to the section are
 
365
simply forgotten.
 
366
Coercions with a local source class or a local target class, and 
 
367
coercions which do not verify the uniform inheritance condition any longer
 
368
are also forgotten.
 
369
 
 
370
\asection{Examples}
 
371
 
 
372
  There are three situations:
 
373
 
 
374
\begin{itemize}
 
375
\item $f~a$ is ill-typed where $f:forall~x:A,B$ and $a:A'$. If there is a
 
376
      coercion path between $A'$ and $A$, $f~a$ is transformed into
 
377
      $f~a'$ where $a'$ is the result of the application of this
 
378
      coercion path to $a$.
 
379
 
 
380
We first give an example of coercion between atomic inductive types
 
381
 
 
382
%\begin{\small}
 
383
\begin{coq_example}
 
384
Definition bool_in_nat (b:bool) := if b then 0 else 1.
 
385
Coercion bool_in_nat : bool >-> nat.
 
386
Check (0 = true).
 
387
Set Printing Coercions.
 
388
Check (0 = true).
 
389
\end{coq_example}
 
390
%\end{small}
 
391
 
 
392
\begin{coq_eval}
 
393
Unset Printing Coercions.
 
394
\end{coq_eval}
 
395
 
 
396
\Warning ``\verb|Check true=O.|'' fails. This is ``normal'' behaviour of
 
397
coercions. To validate \verb|true=O|, the coercion is searched from
 
398
\verb=nat= to \verb=bool=. There is none.
 
399
 
 
400
We give an example of coercion between classes with parameters.
 
401
 
 
402
%\begin{\small}
 
403
\begin{coq_example}
 
404
Parameters
 
405
   (C : nat -> Set) (D : nat -> bool -> Set) (E : bool -> Set).
 
406
Parameter f : forall n:nat, C n -> D (S n) true.
 
407
Coercion f : C >-> D.
 
408
Parameter g : forall (n:nat) (b:bool), D n b -> E b.
 
409
Coercion g : D >-> E.
 
410
Parameter c : C 0.
 
411
Parameter T : E true -> nat.
 
412
Check (T c).
 
413
Set Printing Coercions.
 
414
Check (T c).
 
415
\end{coq_example}
 
416
%\end{small}
 
417
 
 
418
\begin{coq_eval}
 
419
Unset Printing Coercions.
 
420
\end{coq_eval}
 
421
 
 
422
We give now an example using identity coercions.
 
423
 
 
424
%\begin{small}
 
425
\begin{coq_example}
 
426
Definition D' (b:bool) := D 1 b.
 
427
Identity Coercion IdD'D : D' >-> D.
 
428
Print IdD'D.
 
429
Parameter d' : D' true.
 
430
Check (T d').
 
431
Set Printing Coercions.
 
432
Check (T d').
 
433
\end{coq_example}
 
434
%\end{small}
 
435
 
 
436
\begin{coq_eval}
 
437
Unset Printing Coercions.
 
438
\end{coq_eval}
 
439
 
 
440
 
 
441
  In the case of functional arguments, we use the monotonic rule of
 
442
sub-typing.  Approximatively, to coerce $t:forall~x:A, B$ towards
 
443
$forall~x:A',B'$, one have to coerce $A'$ towards $A$ and $B$ towards
 
444
$B'$. An example is given below:
 
445
 
 
446
%\begin{small}
 
447
\begin{coq_example}
 
448
Parameters (A B : Set) (h : A -> B).
 
449
Coercion h : A >-> B.
 
450
Parameter U : (A -> E true) -> nat.
 
451
Parameter t : B -> C 0.
 
452
Check (U t).
 
453
Set Printing Coercions.
 
454
Check (U t).
 
455
\end{coq_example}
 
456
%\end{small}
 
457
 
 
458
\begin{coq_eval}
 
459
Unset Printing Coercions.
 
460
\end{coq_eval}
 
461
 
 
462
  Remark the changes in the result following the modification of the
 
463
previous example.
 
464
 
 
465
%\begin{small}
 
466
\begin{coq_example}
 
467
Parameter U' : (C 0 -> B) -> nat.
 
468
Parameter t' : E true -> A.
 
469
Check (U' t').
 
470
Set Printing Coercions.
 
471
Check (U' t').
 
472
\end{coq_example}
 
473
%\end{small}
 
474
 
 
475
\begin{coq_eval}
 
476
Unset Printing Coercions.
 
477
\end{coq_eval}
 
478
 
 
479
\item An assumption $x:A$ when $A$ is not a type, is ill-typed.  It is
 
480
      replaced by $x:A'$ where $A'$ is the result of the application
 
481
      to $A$ of the coercion path between the class of $A$ and {\tt
 
482
      Sortclass} if it exists.  This case occurs in the abstraction
 
483
      $fun~ x:A => t$, universal quantification $forall~x:A, B$,
 
484
      global variables and parameters of (co-)inductive definitions
 
485
      and functions. In $forall~x:A, B$, such a coercion path may be
 
486
      applied to $B$ also if necessary.
 
487
 
 
488
%\begin{small}
 
489
\begin{coq_example}
 
490
Parameter Graph : Type.
 
491
Parameter Node : Graph -> Type.
 
492
Coercion Node : Graph >-> Sortclass.
 
493
Parameter G : Graph.
 
494
Parameter Arrows : G -> G -> Type.
 
495
Check Arrows.
 
496
Parameter fg : G -> G.
 
497
Check fg.
 
498
Set Printing Coercions.
 
499
Check fg.
 
500
\end{coq_example}
 
501
%\end{small}
 
502
 
 
503
\begin{coq_eval}
 
504
Unset Printing Coercions.
 
505
\end{coq_eval}
 
506
 
 
507
\item $f~a$ is ill-typed because $f:A$ is not a function. The term
 
508
      $f$ is replaced by the term obtained by applying to $f$ the
 
509
      coercion path between $A$ and {\tt Funclass} if it exists.
 
510
 
 
511
%\begin{small}
 
512
\begin{coq_example}
 
513
Parameter bij : Set -> Set -> Set.
 
514
Parameter ap : forall A B:Set, bij A B -> A -> B.
 
515
Coercion ap : bij >-> Funclass.
 
516
Parameter b : bij nat nat.
 
517
Check (b 0).
 
518
Set Printing Coercions.
 
519
Check (b 0).
 
520
\end{coq_example}
 
521
%\end{small}
 
522
 
 
523
\begin{coq_eval}
 
524
Unset Printing Coercions.
 
525
\end{coq_eval}
 
526
 
 
527
Let us see the resulting graph of this session.
 
528
 
 
529
%\begin{small}
 
530
\begin{coq_example}
 
531
Print Graph.
 
532
\end{coq_example}
 
533
%\end{small}
 
534
 
 
535
\end{itemize}
 
536
 
 
537
 
 
538
%%% Local Variables: 
 
539
%%% mode: latex
 
540
%%% TeX-master: "Reference-Manual"
 
541
%%% End: