Skip to content

Commit 0986354

Browse files
committed
Modality example
1 parent 0f7c769 commit 0986354

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

jane/doc/extensions/_04-modes/syntax.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,24 @@ specify a mode along the contention axis, the expression behaves as if it contai
262262
`contended`. This rule still allows you to write e.g. `t @ immutable uncontended`
263263
if that's what you want; most users will never want this, though.
264264

265-
Though this description centers on `immutable` and `contended`, other implications
266-
exist, all to lower users' annotation burden. The implications apply both to
267-
mode expressions and to modality expressions, and are specified by this table:
265+
Once we've done this for modes, it would be odd if we didn't also do this
266+
for modalities. For example, `local` implies `yielding`. Now consider
267+
```ocaml
268+
type 'a glob = { g : 'a @@ global }
269+
let unglob (r : 'a glob @ local) : 'a = r.g
270+
```
271+
Because of the mode implication, `r` has mode `local yielding`. The written
272+
`global` modality means that `r.g` will have mode `global` (corresponding to
273+
the unwritten legacy `global` on the return type of `'a`). But without a
274+
`unyielding` modality, then `r.g` will have mode `yielding`, which is not
275+
compatible with a return expecting the legacy `unyielding`. We thus extend
276+
implications to include modalities, such that `global` implies `unyielding`,
277+
thus getting `unglob` to type-check (because now `r.g` will be `unyielding`).
278+
279+
Other implications
280+
exist, all to lower users' annotation burden, all applying both to modes
281+
and modalities, according to this table:
282+
268283

269284
+---------------+--------------+
270285
| this | implies this |

0 commit comments

Comments
 (0)