dyon icon indicating copy to clipboard operation
dyon copied to clipboard

Move binary and unary operators to external functions

Open bvssvni opened this issue 5 years ago • 6 comments

Instead of treating binary and unary operators as special, they can be turned into external functions. This will simplify the runtime quite a bit.

bvssvni avatar Sep 14 '19 11:09 bvssvni

One problem is that when overriding external functions, the type checker makes wrong assumptions.

bvssvni avatar Sep 14 '19 11:09 bvssvni

The runtime type is not guaranteed, so it might be acceptable to just let the type checker make wrong assumptions and get errors at runtime when something is wrong.

bvssvni avatar Sep 14 '19 11:09 bvssvni

Another solution is to make a type error if one declares a function with same name and incompatible type as the one assumed by the type checker.

bvssvni avatar Sep 14 '19 11:09 bvssvni

Another solution is to add smarter type inference such that the type checker can handle all the cases where the output type depends on the type of the input.

bvssvni avatar Sep 14 '19 11:09 bvssvni

One problem is that && and || are lazy, which means they do not always evaluate the right argument.

bvssvni avatar Sep 17 '19 18:09 bvssvni

A solution to the lazy problem is to add support for making external functions lazy, e.g. by specifying a default value to return, if the argument is evaluated to that value. This requires lazy functions to return same type as the argument which has a default value.

bvssvni avatar Sep 17 '19 19:09 bvssvni