Static constraints

Is it possible to have constraints identified either explicitly by the programmer or implicitly by static analysis that can be used to influence optimization strategies? To what extent is this possible?

if name in array:
    "[name] already exists.";

The algorithm used to search the array depends on whether the array is sorted. In current languages the programmer must explicitly indicate whether to use a linear or binary search.

if array.binarySearch(name):
    "[name] already exists.";

It would be better to specify the constraints that are satisfied and let the compiler decide.

assert: array.isSorted;

if name in array:
    "[name] already exists.";

Best yet would be to have the compiler able to analyze the program and determine that the constraint is satisfied at that point in the program. Then the constraint is implied by previously executed code.

Edit this page | 8 years, 1 month old