language2.mty (749B)
ns app
use io
use math
struct
Vec2 ::
float x
float y
float len() where result >= 0.0 =
math.sqrt(.x ^ 2 + .y ^ 2)
int clamp(int x, int lo, int hi)
where lo <= hi
where result >= lo and result <= hi
=
min(max(x, lo), hi)
pub struct
Reading ::
int sensor
float value
bool valid
bool usable() =
.valid and .value >= 0.0
str label() =
"high" if .value > 100.0 else "normal"
pre #xs > 0
pub float
mean(float[] xs) = +/xs / #xs
pub float[]
values(Reading[] rows) =
rows[.usable()]
| @(.value)
int
main() ::
Reading[] rows = load_readings("readings.csv")
float[] xs = values(rows)
io.put("mean = " + str(mean(xs)))
ret 0