-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFunctorExample.v
More file actions
44 lines (30 loc) · 794 Bytes
/
FunctorExample.v
File metadata and controls
44 lines (30 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(* Use a section to state a fact parametrized on a number n. *)
Section FactsSection.
Variable n : nat.
Theorem my_fact : n >= 0.
Proof.
apply le_0_n.
Qed.
End FactsSection.
(* Outside the section, my_fact is universally quantified. *)
Check my_fact.
(* my_fact
: forall n : nat, n >= 0 *)
(* Alternate approach: use a functor. *)
Module Type NAT_VALUE.
Parameter n : nat.
End NAT_VALUE.
Module FactsFunctor(N : NAT_VALUE).
Theorem my_fact : N.n >= 0.
Proof.
apply le_0_n.
Qed.
End FactsFunctor.
(* To use the fact outside the functor, we must first instantiate the functor. *)
Module Seven.
Definition n := 7.
End Seven.
Module FactsAboutSeven := FactsFunctor(Seven).
Check FactsAboutSeven.my_fact.
(* FactsAboutSeven.my_fact
: Seven.n >= 0 *)