| 1 |
From elpi.apps Require Import NES. |
| 2 |
|
| 3 |
(* Namespaces are like modules, since they let you organize your notions |
| 4 |
and avoid name collisions. |
| 5 |
Namespaces are unlinke modules, since you can always add a notion to |
| 6 |
a namespace, even if the namespace was ended before. *) |
| 7 |
|
| 8 |
NES.Begin This.Is.A.Long.Namespace. |
| 9 |
Definition stuff := 1. |
| 10 |
NES.End This.Is.A.Long.Namespace. |
| 11 |
|
| 12 |
NES.Begin This.Is.A.Long.Namespace. |
| 13 |
Definition more_stuff := stuff. (* stuff in the namespace is visible *) |
| 14 |
NES.End This.Is.A.Long.Namespace. |
| 15 |
|
| 16 |
Print This.Is.A.Long.Namespace.stuff. (* = 1 *) |
| 17 |
Eval compute in This.Is.A.Long.Namespace.more_stuff. (* = 1 *) |
| 18 |
|
| 19 |
(* Unlike a module, a namespace can contain two notions with the same name. |
| 20 |
The latter shadows the former. *) |
| 21 |
|
| 22 |
NES.Begin This.Is.A.Long.Namespace. |
| 23 |
Definition stuff := 2. |
| 24 |
NES.End This.Is.A.Long.Namespace. |
| 25 |
|
| 26 |
(* Binding is static, eg more_stuff still values 1 *) |
| 27 |
Print This.Is.A.Long.Namespace.stuff. (* = 2 *) |
| 28 |
Eval compute in This.Is.A.Long.Namespace.more_stuff. (* = 1 *) |
| 29 |
|
| 30 |
(* Listing and printing namespaces *) |
| 31 |
NES.List This. |
| 32 |
(* |
| 33 |
This_aux_1.This.Is.A.Long.Namespace.stuff (* <-- shadowed *) |
| 34 |
This.Is.A.Long.Namespace.more_stuff |
| 35 |
This.Is.A.Long.Namespace.stuff |
| 36 |
*) |
| 37 |
NES.Print This. |
| 38 |
(* |
| 39 |
This_aux_1.This.Is.A.Long.Namespace.stuff : nat |
| 40 |
This.Is.A.Long.Namespace.more_stuff : nat |
| 41 |
This.Is.A.Long.Namespace.stuff : nat |
| 42 |
*) |
| 43 |
|
| 44 |
(* For convenience one can open a namespace to write short names *) |
| 45 |
NES.Open This.Is.A.Long.Namespace. |
| 46 |
Print stuff. |
| 47 |
|
| 48 |
(* Not quite a name space yet *) |
| 49 |
Structure Default := { sort : Type; default : sort }. |
| 50 |
NES.Begin CS. |
| 51 |
Global Canonical Structure nat_def := {| sort := nat; default := 46 |}. |
| 52 |
Check @default _ : nat. |
| 53 |
NES.End CS. |
| 54 |
Fail Check nat_def. |
| 55 |
(* we want nat_def to live in the CS namespace, BUT |
| 56 |
we want the canonical structure declaration to live outside the namespace *) |
| 57 |
Fail Check @default _ : nat. |
| 58 |
(* This behavior requires Libobject to be aware of the role played by |
| 59 |
a module: if it is a namespace some "actions" have to be propagated upward *) |