on master help sign in
Merge pull request #927 from urbit/dk-molds
c8d2458David Kerschner
tutorials/hoon/molds.md+32−1
@@ -8,7 +8,38 @@ aliases = ["/docs/learn/hoon/hoon-tutorial/molds/"]
8A mold is an idempotent function that coerces a [noun](/docs/glossary/noun/) to
8A mold is an idempotent function that coerces a [noun](/docs/glossary/noun/) to
9be of a specific type or crashes.
9be of a specific type or crashes.
10
10
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.
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+
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.
42+`|$` is the mold builder rune which takes a list of molds and produces a mold.
12
43
13`|$` implements [parametric
44`|$` implements [parametric
14polymorphism](https://en.wikipedia.org/wiki/Parametric_polymorphism) in Hoon,
45polymorphism](https://en.wikipedia.org/wiki/Parametric_polymorphism) in Hoon,