Hi, 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. Gruss, Christian KIS:PEY:2010 Kiselyov et al, Fun with type functions * Nils Schweinsberg <m...@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@haskell.org > http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
pgpkx3Dc2Marv.pgp
Description: PGP signature
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users