A sample revised prelude for numeric classes
12 Feb 2001 11:31:00 +0100
firstname.lastname@example.org (Marcin 'Qrczak' Kowalczyk) writes:
>> Why do you stop at allowing addition on Dollars and not include
>> multiplication by a scalar?
> Perhaps because there is no good universal type for (*).
> Sorry, it would have to have a different symbol.
Is this ubiquitous enough that we should have a *standardized*
different symbol? Any candidates?
>> Having Units as types, with the idea of preventing adding Apples to
>> Oranges, or Dollars to Roubles, is a venerable idea, but is not in
>> widespread use in actual programming languages. Why not?
> It does not scale to more general cases. (m/s) / (s) = (m/s^2),
> so (/) would have to have the type (...) => a -> b -> c, which is not
> generally usable because of ambiguities. Haskell's classes are not
> powerful enough to define full algebra of units.
While it may not be in the language, nothing's stopping you from - and
some will probably encourage you to - implementing e.g. financial
libraries with different data types for different currencies.
Which I think is a better way to handle it, since when you want m to
be divisible by s is rather application dependent.
If I haven't seen further, it is by standing in the footprints of giants