Experience Report: Type-checking Polymorphic Units for Astrophysics Research in Haskell

Takayuki Muranushi
Richard A. Eisenberg, Bryn Mawr College

Abstract

Many of the bugs in scientific programs have their roots in mis- treatment of physical dimensions, via erroneous expressions in the quantity calculus. Now that the type system in the Glasgow Haskell Compiler is rich enough to support type-level integers and other promoted datatypes, we can type-check the quantity calculus in Haskell. In addition to basic dimension-aware arithmetic and unit conversions, our units library features an extensible system of di- mensions and units, a notion of dimensions apart from that of units, and unit polymorphism designed to describe the laws of physics. We demonstrate the utility of units by writing an astrophysics re- search paper. This work is free of unit concerns because every quantity expression in the paper is rigorously type-checked.