Typed laboratory observations
Compute a checked unit bearing rate and temperature rise using exact unit fields, Result propagation and complete local input data.
// Complete local experiment: explicit source units, typed observations and checked rates.
// Requires the updated native Aner development runtime with aner.units.
import aner.units
class Observation {
public let travel: Quantity<m>
public let elapsed: Quantity<s>
public let temperature: Point<degC>
}
fn speed(observation: Observation) -> Result<Quantity<"m/s">, String> {
if observation.elapsed <= 0.0@s { return Result.err("elapsed time must be positive") }
return Result.ok(observation.travel / observation.elapsed)
}
fn report(observation: Observation) -> Result<String, String> {
return Result.ok("Measured speed: " + String(speed(observation)?))
}
fn exceeded(after: Point<degC>, before: Point<degC>,
limit: Quantity<delta_degC> = 5.0@delta_degC) -> Bool {
return after - before >= limit
}
let baseline = 20.0@degC
let observed = Observation(travel: (150.0@cm).to("m"), elapsed: 0.5@s,
temperature: (298.15@K).to("degC"))
print(report(observed).unwrap())
print(observed.temperature - baseline)
print(exceeded(observed.temperature, baseline))
let stalled = Observation(1.5@m, 0.0@s, 25.0@degC)
print(report(stalled).unwrap_err())
Make it your experiment.
With Aner installed, save this program as examples/units_lab_monitoring.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/units_lab_monitoring.aner
aner run examples/units_lab_monitoring.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Use the updated native Aner development runtime with aner.units, checked Quantity and Point types, unit literals and unit bearing arrays. Older packaged executables may predate these features. These complete examples run locally, contain their input fixtures and need no external service or credentials.
Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution