; Fieldtest raw-buf.3 (Axis 2, the (new T ) sugar across ; element types). Task: "store three Float sensor readings and a Bool ; alarm flag in flat buffers, then report the average of the readings, ; doubled if the alarm flag is set." This drives (new RawBuf (con Float) 3) ; and (new RawBuf (con Bool) 1) in one program, so the construction sugar ; and its inference-from-use story are exercised on both the 8-byte ; (Float) and the 1-byte (Bool) element widths. ; ; The element type of each buffer is never written on RawBuf.set/.get; it ; is recovered purely from the values stored (1.5 : Float, true : Bool). ; Straight-line owned `let`-threading (the only shape that currently ; builds for RawBuf — see rawbuf_1/rawbuf_2). ; ; Expected stdout: average (1.5+2.5+3.5)/3 = 2.5, alarm set => doubled ; => 5.0 -> "5.0". (module rawbuf_3_sensor_pair (fn main (type (fn-type (params) (ret (con Unit)) (effects IO))) (params) (body (let readings (new RawBuf (con Float) 3) (let readings (app RawBuf.set readings 0 1.5) (let readings (app RawBuf.set readings 1 2.5) (let readings (app RawBuf.set readings 2 3.5) (let alarm (new RawBuf (con Bool) 1) (let alarm (app RawBuf.set alarm 0 true) (let avg (app / (app + (app RawBuf.get readings 0) (app + (app RawBuf.get readings 1) (app RawBuf.get readings 2))) 3.0) (app print (if (app RawBuf.get alarm 0) (app * avg 2.0) avg))))))))))))