[Haskell-cafe] GSoC proposal: Units for GHC

Nils Schweinsberg ml at n-sch.de
Wed Apr 4 14:17:01 CEST 2012


Am 04.04.2012 13:48, schrieb Jurriën Stutterheim:
> This sounds pretty cool and useful. How much of this can be implemented in a library and how much of this would need to be supported on a compiler level? Ideally, most of this would be solved on the library level.

The compiler would have to know how to "typecheck" units, e.g. the 
addition (+) would combine two values of the same unit, the (/) 
operation would divide them:

   (+) :: <a> -> <a> -> <a>
   (/) :: <a> -> <b> -> <a/b>

The idea is to have the compiler complain whenever you try to add <b> to 
<a> or if you expect something other than <a/b> as result from a 
division. This would require modifications to GHC at compiler level. A 
library could offer some basic units (SI units for example) and maybe 
even unit aliases ("<N> = <kg*m/s^2>"), but I don't see how the "core" 
of this "unit verification system" could be placed into a library.


- Nils



More information about the Glasgow-haskell-users mailing list