Skip to content

Commit 97f8528

Browse files
authored
Merge pull request #711 from lean-ja/Seasawher/issue709
protected は帰納型のコンストラクタにも使用できる
2 parents f27bcb4 + 1f572b5 commit 97f8528

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Examples/Command/Declarative/Protected.lean

+43
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# protected
33
`protected` は、ある名前空間 `Hoge` にある定義 `foo` に対して、必ずフルネームの `Hoge.foo` でアクセスすることを強要するものです。
44
-/
5+
section --#
56
structure Point where
67
x : Nat
78
y : Nat
@@ -29,3 +30,45 @@ open Point
2930

3031
-- フルネームならアクセスできる
3132
#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 --#

0 commit comments

Comments
 (0)