Skip to content

Commit 4785d0c

Browse files
committed
and inherit section to language basics
1 parent 3261620 commit 4785d0c

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

src/ch05-01-language-basics.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44

55
These values are mostly similar to JSON:
66

7-
| Type | Description | Example
8-
|---|---|---|
9-
| integer | Whole number | 1 |
10-
| float | Floating point number | 1.054 |
11-
| string | UTF-8 string | "hello!" |
12-
| path | File or url | ./default.nix |
7+
| Type | Description | Example
8+
|---------------|-----------------------|------------------|
9+
| integer | Whole number | 1 |
10+
| float | Floating point number | 1.054 |
11+
| string | UTF-8 string | "hello!" |
12+
| path | File or url | ./default.nix |
13+
14+
And these are the collection:
15+
| Type | Description | Example
16+
|---------------|--------------------------|------------------|
17+
| list | Multi-type list | ["hello" 1] |
18+
| attribute set | Key value structure | {key = "value";} |
1319

1420
*NOTE*: Paths are special. They will be resolved relative to the file.
1521
They must start with a "." or "/", similar to how they would be expressed in a shell.
@@ -112,6 +118,30 @@ let expressions work similarly to how they work in Haskell.
112118
sha256 = "...";
113119
};
114120
```
121+
122+
## Inherit statements
123+
124+
An inherit statement can be used to _pull_ values out of a parent scope
125+
into the current one. Values are whitespace separated and the statement
126+
ends with a `;`.
127+
128+
If an attribute set in parenthesis follows immediately after the `inherit`
129+
keyword, then values can also be pulled directly out of the given set.
130+
131+
In a `let` block, inherit statements can also come before the values they
132+
reference, so long as they are in the same block.
133+
134+
```
135+
let
136+
inherit (set.values) name version;
137+
138+
set.values = {
139+
name = "package";
140+
version = "0.1.0";
141+
};
142+
in
143+
{ inherit name version; }
144+
```
115145

116146
## With expressions
117147

0 commit comments

Comments
 (0)