Skip to content

Commit 3db5562

Browse files
committed
update RFCs following discussions
1 parent d0c25ec commit 3db5562

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

rfcs/val_annotations.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,15 @@ let rev li =
7878

7979
## Discussion and extensions
8080

81+
The suggestions below are *not* intended for inclusion as part of the
82+
RFC (they would not be implemented along with what's above), but they
83+
serve to record and discuss alternative choices, and/or to check
84+
compatibility with other features by showing that the feature can be
85+
extended if desired.
86+
8187
### Locally abstract types in `val` declarations
8288

83-
We propose to extend the form `type a . ...` to work with value
89+
One can consider extending the form `type a . ...` to work with value
8490
annotations. For example:
8591

8692
```ocaml
@@ -94,7 +100,7 @@ let mem elt li =
94100

95101
Notice that `type a` binds the variable `a` in both the declaration and the definition.
96102

97-
(This extension could be left out of a first implementation of this proposal.)
103+
This extension may not be necessary if [#12732](https://github.com/ocaml/ocaml/pull/12732) is merged. In general there are discussions around the semantics of `type a` vs `'a` that are independent of the present PR. We merely point out that `val` could scale to `type a.` if desired.
98104

99105

100106
### Alternative syntax: declarations within `let` blocks
@@ -128,6 +134,7 @@ let rev li =
128134
in loop li []
129135
```
130136

137+
131138
### Combination with `_` inference from signature
132139

133140
oxcaml has a work-in-progress feature where `_` can be used to elide types and module signatures in structures (in particular `.ml` files), when they are declared in the corresponding signature (in particular the `.mli` file), see https://github.com/oxcaml/oxcaml/pull/2783 . This feature is independent, but it was part of the motivation to revive the current proposal, as it can naturally be combined:
@@ -136,3 +143,47 @@ oxcaml has a work-in-progress feature where `_` can be used to elide types and m
136143
val map : _
137144
let rec map f li = ...
138145
```
146+
147+
A more compact form specific to toplevel `let` definitions could be
148+
considered:
149+
150+
```
151+
val rec map f li = ...
152+
```
153+
154+
it would both imply `val map : _` as above and could only be included
155+
once per structure (shadowing `val` declarations with another `val` is
156+
forbidden.)
157+
158+
159+
### Tension with using `val` for forward-declaration
160+
161+
Jeremy Yallop points out that `val` could be considered to introduce recursion, so that
162+
163+
```
164+
let rec fac n = function
165+
| 0 -> 1
166+
| n -> n * fac (n - 1)
167+
```
168+
169+
could also be written (note the absence of `rec` below)
170+
171+
```
172+
val fac : int -> int
173+
let fac n = function
174+
| 0 -> 1
175+
| n -> n * fac (n - 1)
176+
```
177+
178+
That interpretation of `val` is *incompatible* with the one proposed in this PR, as their semantics would differ in the following case:
179+
180+
```
181+
let fac n = 0 (* first definition *)
182+
183+
val fac : int -> int
184+
let fac n = function
185+
| 0 -> 1
186+
| n -> n * fac (n - 1) (* first definition or recursive occurrence? *)
187+
```
188+
189+
Leo White proposes to use `val rec` to implicitly introduce recursion, to avoid the incompatibility between the two features. (Gabriel Scherer and Kate Deplaix alternatively proposed to require `let rec` to take `val` forward declarations into account, but Jeremy Yallop was not impressed by this proposal.)

0 commit comments

Comments
 (0)