on master help sign in
issue #806

updated mold descriptions

commit2ce966442aa1f3a480014b42ec700d4ff89d2583 authorDavid Kerschner <dkerschner@hcoop.net> dateThu 6 Aug 2020, 13:29 (6 years ago) parent4072835
1 file changed+45−1
tutorials/hoon/molds.md+45−1
tutorials/hoon/molds.md+45−1
@@ -8,7 +8,51 @@ aliases = ["/docs/learn/hoon/hoon-tutorial/molds/"]
88A mold is an idempotent function that coerces a [noun](/docs/glossary/noun/) to
99be of a specific type or crashes.
1010
11−`|$` is a new rune as of the writing of this document so you may see this spelled in slightly different way if you don't have the latest version of `hoon.hoon`. `|$` is the mold builder rune which takes a list of molds and produces a mold.
11+
12+The simplest molds to understand are arms of cores created with `+$`
13+
14+```
15++$ height [feet=@ud inches=@ud]
16+```
17+
18+A mold is compiled to a gate that takes in any noun and produces a typed value, or crashes:
19+
20+```
21+(height [5 11])
22+:: produces [feet=5 inches=11]
23+```
24+```
25+(height %wrong)
26+:: crashes
27+```
28+
29+To coerce using a gate, it's good practice to use the `;;` rune, which can parse inline molds without requiring a comma:
30+
31+
32+```
33+;;(height [5 11])
34+:: produces [feet=5 inches=11]
35+```
36+```hoon
37+;;([feet=@ud inches=@ud] [5 11])
38+:: produces [feet=5 inches=11]
39+```
40+
41+
42+Without using `;;`, you would have to start the mold definition with a comma in order for it to be parsed as a mold, not just as a pair of gates with faces on them:
43+
44+
45+```hoon
46+(,[feet=@ud inches=@ud] [5 11])
47+:: produces [feet=5 inches=11]
48+
49+
50+([feet=@ud inches=@ud] [5 11])
51+:: compiler error, can't find $ at axis 2 because this is a pair, not a mold
52+```
53+
54+
55+`|$` is the mold builder rune which takes a list of molds and produces a mold.
1256
1357`|$` implements [parametric
1458polymorphism](https://en.wikipedia.org/wiki/Parametric_polymorphism) in Hoon,