This commit is contained in:
2026-06-16 01:27:54 +09:00
parent 5d6a03b74f
commit 4e82f47f90
31 changed files with 141 additions and 112 deletions
+10 -10
View File
@@ -6,7 +6,7 @@
`&` は値・制約・構造を合成する演算子である。
```n
```dcdl
A & B
```
@@ -22,7 +22,7 @@ A & B
例:
```n
```dcdl
Port = Int & >= 1 & <= 65535;
NarrowedPort = Port & > 443;
@@ -45,7 +45,7 @@ NarrowedPort & 8000
一方、以下は失敗する。
```n
```dcdl
BadConfig = MyConfig & {
port = 80;
};
@@ -58,7 +58,7 @@ BadConfig = MyConfig & {
`//` は右辺優先の構造的 patch 演算子である。
`&` が制約を保った合成であるのに対し、`//` は設定やスキーマを上書き・変更するために使う。
```n
```dcdl
A // B
```
@@ -74,7 +74,7 @@ A // B
つまり `//` は shallow merge ではなく deep patch とする。
```n
```dcdl
Base = {
feature_hoge = {
enable = Bool default true;
@@ -91,7 +91,7 @@ Patched = Base // {
`Patched` は以下に相当する。
```n
```dcdl
{
feature_hoge = {
enable = false;
@@ -102,7 +102,7 @@ Patched = Base // {
ドットパスを使うと以下のようにも書ける。
```n
```dcdl
Patched = Base // {
feature_hoge.enable = false;
};
@@ -114,7 +114,7 @@ Patched = Base // {
候補として、`replace(...)` を組み込み関数として提供する。
```n
```dcdl
Replaced = Base // {
feature_hoge = replace({
enable = false;
@@ -128,7 +128,7 @@ Replaced = Base // {
`&` は制約を満たす具体化に使う。
```n
```dcdl
ValidConfig = MyConfig & {
port = 8000;
};
@@ -136,7 +136,7 @@ ValidConfig = MyConfig & {
`//` は既存構造の上書きや変形に使う。
```n
```dcdl
ModifiedSchema = MyConfig // {
port = Int default 9000;
};