DaphneDSL supports typed and untyped parameters to user-defined functions. For untyped parameters, a value of any type could be provided, and the function body is compiled and optimized for that type; here anything is valid at the call-site. For typed paramters, there is exactly one acceptable type for the given value.
Currently, when a value of a wrong type is passed to a typed parameter, this causes an error. Currently, the user must explicitly cast the value to the right type, which is annoying given that the expected type is anyway clear. To mitigate this problem and for consistency with the bahavior of DaphneDSL's built-in functions, the values provided for typed parameters of UDFs should automatically be casted to the expected type.
Example:
Given the following UDF, where x is an untyped parameter and y is a typed parameter:
def foo(x, y:si64) {
print(x);
print(y);
}
The following calls are valid and yield the output:
foo(1, 2);
print("");
foo([1.1, 2.2], 3);
1
2
DenseMatrix(2x1, double)
1.1
2.2
3
The following call is invalid and yields the following error:
foo(1, 2.2);
[error]: Parser error: my-example.daphne:8:0 no definition of function `foo` for argument types (si64, f64), available options: foo(!daphne.Unknown, si64)
It can be manually rewritten to the following to make it valid. But that should happen automatically and transparently under the covers.:
DaphneDSL supports typed and untyped parameters to user-defined functions. For untyped parameters, a value of any type could be provided, and the function body is compiled and optimized for that type; here anything is valid at the call-site. For typed paramters, there is exactly one acceptable type for the given value.
Currently, when a value of a wrong type is passed to a typed parameter, this causes an error. Currently, the user must explicitly cast the value to the right type, which is annoying given that the expected type is anyway clear. To mitigate this problem and for consistency with the bahavior of DaphneDSL's built-in functions, the values provided for typed parameters of UDFs should automatically be casted to the expected type.
Example: Given the following UDF, where
x
is an untyped parameter andy
is a typed parameter:The following calls are valid and yield the output:
The following call is invalid and yields the following error:
It can be manually rewritten to the following to make it valid. But that should happen automatically and transparently under the covers.: