[Haskell-cafe] Perl-style numeric type

Henning Thielemann lemming at henning-thielemann.de
Wed Jun 20 06:14:21 EDT 2007


On Tue, 19 Jun 2007, Brent Yorgey wrote:

> But before I get too far (it looks like it will be straightforward yet
> tedious to implement), I thought I would throw the idea out there and see if
> anyone knows of anything similar that has already been done before (a
> cursory search of the wiki didn't turn up anything).  I don't want to
> reinvent the wheel here.

Do you have some examples, where such a data type is really superior to
strong typing? There are examples like computing the average, where a
natural number must be converted to a different type:
  average xs = sum xs / fromIntegral (length xs)
 but this one can easily replaced by
  average xs = sum xs / genericLength xs

 Thus, before you spend much time on making Haskell closer to Perl, how
about collecting such examples, work out ways how to solve them elegantly
in the presence of strong typing and set up a wiki page explaining how to
work with strongly typed numbers? I think, this topic really belongs to
  http://www.haskell.org/haskellwiki/Category:FAQ
 Strongly typed numbers are there for good reason: There is not one type
that can emulate the others. Floating point numbers are imprecise, a/b*b=a
does not hold in general. Rationals are precise but pi and sqrt 2 are not
rational. People have designed languages again and again which ignore
this, and they failed. See e.g. MatLab which emulates an integer (and even
a boolean value) by a complex valued 1x1 matrix.


More information about the Haskell-Cafe mailing list