Consider adding type contracting (protocols/interfaces/abstract types) #9
Labels
semantics.interpreter
Any issue relating to changing the semantics of interpreter code.
semantics
Generic label for semantics issues. All semantics issues should have this tag.
syntax
Any issue relating to the syntax of Myst.
In dynamic, interpreted languages, the ability to define explicit contracts about the interfaces that values expose is often lost. Instead, these are traded for abstract definitions and/or implicit contracts that are often visually simpler, but less obvious when the contract is extended or re-implemented by another class/module.
The primary loss in these languages is the ability to enforce those contract requirements before they are encountered at runtime (if they ever are).
Another great side-effect of being able to enforce those contracts is predictable failure. That is, if a function requires that a contract be satisfied, then calls to that function with non-conforming arguments will fail before any of the function's body is executed. When the contract is not enforceable, it is common for functions to begin execution and fail midway through, resulting in a greater (often inferred, not necessary) dependence on exceptions and exception handling.
I think having Myst adopt a contracting system would be beneficial and worthwhile, and doesn't have to compromise readability or flexibility in the language. The roadmap for Myst already suggests explicit typing will be idiomatic in most cases, so the ability to specify more abstract behaviors follows suit to me.
Examples of languages that implement and enforce contracting systems:
Some considerations:
use
orimplements
directive at a module/class level for defining the contracts that the type should satisfy.The text was updated successfully, but these errors were encountered: