Units of Measure in F#

BCS ao at pathlink.com
Mon Oct 6 14:50:57 PDT 2008


Reply to bearophile,

> I have found this interesting old thread, I don't know how much those
> things are true today too:
> http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmar
> s.D&article_id=36939
> 
> Beside allowing algebraic data types, that are quite useful, a
> functional-like type system allows to implement Units of Measure in a
> nice way:
> 
> http://blogs.msdn.com/andrewkennedy/archive/2008/08/20/units-of-measur
> e-in-f-part-one-introducing-units.aspx
> 
> For people that don't remember what algebraic data types are:
> http://en.wikipedia.org/wiki/Algebraic_data_type
> 
> This power also allows to use pattern matching, absent in Python,
> present in Haskell, Ocaml, Scala, etc.
> 
> Bye,
> bearophile

I think it is fully doable right now. I've considered doing it off and on 
for some time. I even figured out how to make it do rational powers for the 
dimensions.

The only thing I would want is to be able to avoid needing to wrap everything 
by way of operator overloads on typedefs

typedef real Unit(..stuff..)
{
   Unit!(stuff) opAdd(T)(T t) {...}
}

and some way to re-type functions

alias sqrt Unit!(stuff/2) sqrt(Unit!(stuff));  // if sqrt called with Unit!(stuff), 
return type is Unit!(stuff/2)





More information about the Digitalmars-d mailing list