===================
== Martin Trojer ==
Programming Blog

===================

Announcing Frins, a practical unit of measure calculator DSL for Scala

scala frinj frins

I am proud to announce a new Scala project called “Frins.”

Frins is a practical unit-of-measure calculator DSL for Scala.

Key features:

  • Tracks units of measure through all calculations, allowing you to mix units of measure transparently
  • Comes with a huge database of units and conversion factors
  • Inspired by the Frink project

Full source code is available on GitHub.

To whet your appetite, head straight over to the example calculations.

How Frins Came About

About a year ago, I created Frinj. With Frinj, I tried to marry some of the joys of one of my favorite programming languages (Frink) with the Clojure REPL. I was quite pleased with the results, and the response was encouraging.

Recently, I started reading Odersky (again), and when I came to the chapter on implicit conversions, I got the idea of trying to create a Frinj-style DSL for the Scala interpreter. I could leverage some of the efforts made in Frinj (like parsing the Frink unit database), and the result is quite cool.

It’s indeed possible to create a very fluent and powerful DSL using some of Scala’s core language constructs!

// If you took the matter in a teaspoon of water, and converted that to energy,
// how many gallons of gasoline would you have to burn to get an equal amount of energy?

scala> 'teaspoon * 'water * ('c ** 2) to 'gallons * 'gasoline
res0: frins.NumberT = 3164209.862836101  [dimensionless]