Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to implement F#'s infrastructure for Units of Measurement in Scala?

F# ships with special support for a unit of measurement system, which provides static type safety while compiling down to the numeric types instead of burdening the runtime with wrapping/unwrapping operations.

Is it possible to use some of Scala's type system magic to implement something comparable to that?

like image 757
soc Avatar asked Sep 20 '11 15:09

soc


2 Answers

The answer is no.

Now, someone is bound to point me to Scalar, but that gives runtime checking. Perhaps, then, point to the efforts of Jesper Nordenberg's type-safe units or Jim McBeath's take on it, but these are cumbersome and awkward.

I'll point, instead to the Units compiler plugin. It gave Scala, back in 2008/2009, a pretty good system of units, as can be seen in this post. It did so, however, by extending the compiler, which would not be necessary if the type system was enough. Alas, it has not been maintained and it doesn't work anymore.

like image 124
Daniel C. Sobral Avatar answered Oct 19 '22 07:10

Daniel C. Sobral


I don't know anything about it, but I just stumbled accross this talk at Scala Days: https://wiki.scala-lang.org/display/SW/ScalaDays+2011+Resources#ScalaDays2011Resources-ScalaUImplementingaScalalibraryforUnitsofMeasure

like image 36
Kim Stebel Avatar answered Oct 19 '22 08:10

Kim Stebel