File tree 1 file changed +43
-0
lines changed
Examples/Command/Declarative
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 2
2
# protected
3
3
`protected` は、ある名前空間 `Hoge` にある定義 `foo` に対して、必ずフルネームの `Hoge.foo` でアクセスすることを強要するものです。
4
4
-/
5
+ section --#
5
6
structure Point where
6
7
x : Nat
7
8
y : Nat
@@ -29,3 +30,45 @@ open Point
29
30
30
31
-- フルネームならアクセスできる
31
32
#check Point.sub
33
+
34
+ end --#
35
+ /- ## protected def 以外の用法
36
+
37
+ `def` コマンドに対してだけでなく、[ `indudctive` ] (./Inductive.md) コマンドで生成されるコンストラクタに対しても使用可能です。-/
38
+ section --#
39
+
40
+ /-- 2分木 -/
41
+ inductive BinTree (α : Type ) where
42
+ | empty : BinTree α
43
+ | protected node : α → BinTree α → BinTree α → BinTree α
44
+
45
+ -- 名前空間を開く
46
+ open BinTree
47
+
48
+ -- 名前空間を開いているのに、
49
+ -- コンストラクタに短い名前でアクセスできない
50
+ #check_failure node
51
+ #check BinTree.node
52
+
53
+ -- protected でない方は短い名前でアクセスできる
54
+ #check empty
55
+
56
+ end --#
57
+ /- また [ `structure` ] (./Structure.md) コマンドで生成されるアクセサ関数やコンストラクタに対しても使用可能です。 -/
58
+ section --#
59
+ structure Foo where
60
+ -- コンストラクタも protected にできる
61
+ protected mk ::
62
+
63
+ bar : Nat
64
+ protected baz : String
65
+
66
+ open Foo
67
+
68
+ -- 名前空間を開いているので bar には短い名前でアクセスできる
69
+ #check bar
70
+
71
+ -- baz には短い名前でアクセスできない
72
+ #check_failure baz
73
+
74
+ end --#
You can’t perform that action at this time.
0 commit comments