Problems displaying values with units; math with values that have units generally

Oooh, nice! Exactly, thanks for that!

If we include your extension, we can write a type-generic abstraction like this (modified from above):

To decide which K is the result of (F - a phrase real number -> real number) of (original - arithmetic value of kind K):
	let neutral-element be the unit value of K;
	let original-as-real be original divided by neutral-element;
	let r be F applied to original-as-real;
	let result be r multiplied by neutral-element;
	decide on result.

Which lets us apply the real-to-real functions to other kinds of values, like mass, for example:

let m1 be 5.678kg;
say "The floor of m1 is [result of floor function of m1].";
say "The ceiling of m1 is [result of ceiling function of m1].";
[... etc.]

(If we have defined mass before, of course: “Mass is a kind of value. 1.0kg (in metric units, in kg) or 1 kilogram (in kilograms, singular) or 2 kilograms (in kilograms, plural) specifies a mass.”)

Quite possibly there are simpler ways to do all this, but it was fun to tinker with it. :slight_smile:

2 Likes