MIFFS Is Fun For Sums

by rich

Units

MIFFS supports linear units via the built-in datatypes unit and scalar and the built-in function in : scalar * unit -> scalar.

You cannot write units and scalar expressions in exactly the same way you would in scientific notation, you are still constrained by the syntax of the language. Basically, applying a number to a unit gives a scalar, and arithmetic with scalars and units works more or less how it should. You may find that you need to add brackets occasionally to force the correct precedence on an expression if you write it in scientific notation.

Naming Units

Normally, units are values like any other in MIFFS. There is a slight cheat in that if you create a new unit with a val declaration, it will pick up the name from the variable name. For example:

val chain = 66 * feet;
val chain = chain : unit;
11 yard in chain;
val ans = 0.5 chain : scalar

Base units

Units which cannot be defined in terms of existing units are baseunits. They can be defined with a special statement:

baseunit kg;
val kg = unit;

This statement will declare a new physical dimension, from which other units can be derived. The SI physical dimensions are already declared for you in the default environment, so you should not normally need to use this statement.

Built-in units

A fair selection of units are defined in the default MIFFS environment. If you are using the Readline frontend, you can tab-complete through the defined units, or use the vals builtin function to list them. If you want a comprehensive unit conversion package, try GNU Units.