[racket] Units/measures library

From: Stephen Bloch (sbloch at adelphi.edu)
Date: Thu Nov 17 08:59:46 EST 2011

On Nov 17, 2011, at 8:06 AM, Matthias Felleisen wrote:

> 
> I can imagine two things at least: 
> 
> 1. a conversion library with functions such as feet->meter and celsius->fahrenheit and grams->ounces. 
> 
> 2. a refined version of TR that statically checks units. 
> 
> I assume Jose was interested in the first -- Matthias

I would be much more interested in the latter; the former is a first-semester student exercise.

Microsoft's F# language has unit support in its type system.  I don't remember many of the details, but it seemed like the sort of thing that could easily be implemented in Racket.  Define a type that combines a number with a "unit", which is a ratio of monomials in unit symbols (e.g. g-cm^2/sec^2); define arithmetic operators that work correctly on these, including raising an error when somebody tries to add or subtract things with different units; define input and output formats for this type.  The checking wouldn't necessarily have to be static, as far as I'm concerned.  I don't know whether it would be feasible to apply previously-written mathematical functions (e.g. for/add, for/multiply, max, min) to these unitized quantities, or whether someone would need to re-implement those things using the unitized arithmetic.


Stephen Bloch
sbloch at adelphi.edu




Posted on the users mailing list.