walt
walt copied to clipboard
Generics
https://flow.org/en/docs/types/generics/ can be useful when dealing with either i32, i64, f32 or f64 i/o
Hi,
I think this would improve developer ergonomics, which is important.
It would also mean additional layers of abstraction over compiled bytecode. One of my primary goals, at this time, is to keep the generated WASM as close to the input Walt source as possible. Compiling generic types would be counterproductive to that goal.
It's important to me that the syntax produces predictable results. I don't think that's possible to maintain with generic types at this point. I would be open to them in the future though. At the very least we would need a pretty solid parser and optimizer to output something like this efficiently:
function add<T>(x: T, y: T): T {
return x + y;
}
export function test(): i32 {
const x: i32 = add(2, 2);
const y: f32 = add(2, 2);
const z: i64 = add(2, 2);
return x;
}
Maybe an alternative to the generics we know from C++ or Java would be hygienic macros? Julia has a very good section on it. It's basically a pre-processor but sane. I don't know if that helps with @ballercat's goal of keeping the abstractions transparent and predictable though.