Add an easier way to check function params
- Dominant language
- Jsonnet
- Stars
- 7.6k
- Forks
- 475
- PR merge metrics
- No merged PRs in 30d
Description
@huggsboson asked "Any interest in static or dynamically checked type assertions on parameters?"
You're the first to draw attention to this.
We decided pretty early on that dynamic typing would be most approachable. It fits in better with the laziness and dynamic binding, and avoids all the syntactic overhead of type annotations. There was a previous language that used type inference (HM system) but people found the unification errors hard to understand. Adding some form of gradual typing into the language now would probably be a bit incongruous. However some middle ground might be to have a dynamic checking framework, e.g. maybe something that looks like:
```
local f(x, y) =
assert std.check({x: x, y: y}, { ... some spec here ... });
...
```
This is just a library addition That would allow consistent and (relatively) concise checking of function preconditions for libraries. It could also be conservatively interpreted by linting tools. We could add more syntax sugar to make it even more concise:
```
local f(x, y) =
checkparams { ... some spec here ... };
....
```
The hardest problem here is defining what the spec should be -- how expressive is it, should it use some existing thing or subset of an existing thing (jsonschema is probably overkill).
Contributor guide
Assessment
This issue has not been assessed yet.