3 ms·
I'm the last person to talk about type theory, but on the max function example: fn max(comptime T: type, a: T, b: T) -> T { if (a > b) a else b } fn letsTr
by FrancoDiaz 10y ago
I'm the last person to talk about type theory, but on the max function example:
fn max(comptime T: type, a: T, b: T) -> T {
if (a > b) a else b
}
fn letsTryToPassARuntimeType(condition: bool) {
const result = max(
if (condition) f32 else u64,
1234,
5678);
}
Then we get this result from the compiler:
./test.zig:6:9: error: unable to evaluate constant expression
if (condition) f32 else u64,
^
Couldn't the compiler infer some kind of union type. You don't know the type at runtime, but f32 or u64 is a legit comparision type.