[Haskell-cafe] GSoC proposal: Units for GHC

Christian Hoener zu Siederdissen choener at tbi.univie.ac.at
Wed Apr 4 14:55:58 CEST 2012


Most, if not all could reasonably be implemented using type families --
though there is a potential O(n^2) instance problem. In KIS:PEY:2010,
there is an example for addition which you could look at.

That is, using the example

(1::Int) + (1::Double) would work out to (2::Double) instead of a
compile-time error.

The paper is probably a very good read for you.


Kiselyov et al, Fun with type functions

* Nils Schweinsberg <ml at n-sch.de> [04.04.2012 14:18]:
> 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
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20120404/a6c3123b/attachment.pgp>

More information about the Glasgow-haskell-users mailing list