// impl Protocol for built-in scalar types (f32, i64, bool, u32, ...) —
// both static dispatch (`f32.lerp(...)`) and protocol-boxed dispatch via
// `#inline` erasure.

Lerpable :: protocol #inline {
    lerp :: (b: Self, t: f32) -> Self;
}

impl Lerpable for f32 {
    lerp :: (self: f32, b: f32, t: f32) -> f32 { self + (b - self) * t }
}

do_lerp :: (a: Lerpable, b: f32, t: f32) -> f32 {
    a.lerp(b, t)
}

main :: () -> void {
    // Static call through impl
    result := f32.lerp(0.0, 10.0, 0.5);
    print("lerp(0, 10, 0.5) = {}\n", result);

    // Protocol dispatch through #inline erasure
    val : f32 = 0.0;
    p : *f32 = @val;
    l : Lerpable = xx p;
    result2 := do_lerp(l, 10.0, 0.25);
    print("lerp(0, 10, 0.25) = {}\n", result2);
}

#import "modules/std.sx";
