[racket] Units/measures library

From: José Lopes (jose.lopes at ist.utl.pt)
Date: Thu Nov 17 09:38:26 EST 2011


I am working with architects, therefore, I am interested in defining several
length units (e.g., metre, millimetre and so on) so that they can
create geometry using the units that are more appropriate for the
problem at hand. Arithmetic operators are also important and conversion
functions as Matthias mentioned.

I also agree with Stephen, F# is a good source of inspiration.

However, what would be really great (for my work at least :) ) was if 
operators worked transparently both with simple numbers (i.e., numbers
without units) and numbers with units. Because otherwise I am going to have
to load several of my functions with dispatch code to deal with simple 
and unit numbers appropriately.


On 17-11-2011 21:59, Stephen Bloch wrote:
> 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
> _________________________________________________
>    For list-related administrative tasks:
>    http://lists.racket-lang.org/listinfo/users

José António Branquinho de Oliveira Lopes
58612 - MEIC-A
jose.lopes at ist.utl.pt

Posted on the users mailing list.