on master help sign in
micgal entry
commita434ddc14848867d932cde3d6f9b8a53b7e3b66b authordrbeefsupreme <drbeefsupreme@discordja.net> dateFri 26 Mar 2021, 13:14 (6 years ago) parentb714054
1 file changed+91
hoon/reference/rune/mic.md+91
hoon/reference/rune/mic.md+91
@@ -59,6 +59,97 @@ Irregular: `:(add a b c)` is `;:(add a b c)`.
595912
6060```
6161
62+### `;<` "micgal"
63+
64+`[%mcgl p=spec q=hoon r=hoon s=hoon]`: monadic do notation.
65+
66+##### Syntax
67+
68+Regular: **4-fixed**
69+
70+```hoon
71+;< mold=mold bind=hoon expr1=hoon expr2=hoon
72+```
73+
74+#### Semantics
75+
76+A `;<` is for sequencing two computations, `expr1` and `expr2`, using a provided
77+implementation of monadic bind. This rune takes a gate `bind` which takes a mold
78+`mold` and produces an implementation of monadic bind.
79+
80+##### Desugaring
81+
82+```hoon
83+%+
84+ (q ^:p)
85+r
86+|= p
87+ s
88+```
89+
90+##### Discussion
91+
92+`;<` is much like Haskell `do` notation. You have a sequence of events you'd
93+like to run such that each past the first depends on the output of the previous
94+one. The output of the previous one may not be of the correct type to use as an
95+input to the next one, and so an adapter such as `+bind` or `+biff` is needed.
96+
97+`;<` differs from [`;~`](#micsig) in that it takes a gate which takes a mold
98+that produces an implementation of monadic bind, rather than taking an
99+implementation of monadic bind directly.
100+
101+`;<` can be used to glue a pipeline together to run an asynchronous function or event. This can be helpful when deferring parts of a computation based on external data.
102+
103+We remark that you can switch binds in the middle of a sequence of `;<`.
104+
105+##### Examples
106+
107+[`+biff`](@/docs/hoon/reference/stdlib/2a/#biff) is the unit monad's
108+implementation of monadic bind. That is to say, it takes a unit `a` and a gate
109+`b` that accepts a noun that produces a unit, and extracts the value from `a` to
110+pass as a sample to `b`. [`+bind`](@/docs/hoon/reference/stdlib/2a/#bind) takes
111+a unit `a` and a gate `b` that neither accepts nor produces a unit, and applies
112+`b` to the value of `a` and produces a unit. Note that if you do pass `+bind` a
113+gate that produces a unit, `+bind` will treat it as though it does not.
114+
115+We illustrate the usage of `;<`, `+biff`, and `+bind` with a `map` of atoms.
116+```
117+~zod:dojo> =m (my ~[[1 3] [2 2] [3 1]])
118+ > (~(get by m) 1)
119+ [~ 3]
120+```
121+A single usage of `;<` only serves to apply the binding function to the output
122+of `expr1`:
123+```
124+~zod:dojo> ;< a=@ _bind (~(get by m) 1)
125+ a
126+ [~ 3]
127+~zod:dojo> ;< a=@ _biff (~(get by m) 1)
128+ a
129+ 3
130+```
131+Here we see the results of chaining them together:
132+```
133+~zod:dojo> ;< a=@ _biff (~(get by m) 1)
134+ ;< b=@ _biff (~(get by m) a)
135+ b
136+ 1
137+~zod:dojo> ;< a=@ _bind (~(get by m) 1)
138+ ;< b=@ _biff (~(get by m) a)
139+ b
140+ [~ 1]
141+~zod:dojo> ;< a=@ _biff (~(get by m) 1)
142+ ;< b=@ _bind (~(get by m) a)
143+ b
144+ [~ 1]
145+~zod:dojo> ;< a=@ _bind (~(get by m) 1)
146+ ;< b=@ _bind (~(get by m) a)
147+ b
148+ [~ [~ 1]]
149+```
150+
151+
152+
62153### `;+` "miclus"
63154
64155make a single XML node (Sail)