differential-datalog
differential-datalog copied to clipboard
Automatic string conversion for type variables
At the moment, the compiler refuses to convert type variables to strings.
This can be fixed by:
- Infering that a function expects a type variable to be printable
- In the generated Rust function, add the Display trait for this function
- Whenever the function is called, check that its concrete arguments satisfy the trait
- Implement Display trait for types that have a user-defined 2String method
Here's a function that I wrote that will compile to Rust, then won't compile at that point. I think it's exactly this issue:
function stringize_and_join(vec: Vec<'A>, sep: string): string {
var strings: Vec<string> = vec_with_capacity(vec_len(vec));
for (x in vec) {
vec_push(strings, __builtin_2string(x))
};
string_join(strings, sep)
}
Yes, exactly. There is no easy fix at the moment. We don't have the notion of traits or interfaces or anything like that, so there is no way to define a function that only accepts printable arguments.