Philip K.F. Hölzenspies wrote:
You can have a look at the Number module here:

http://www.cs.utwente.nl/~holzensp/Number.hs

Now, whenever I've hacked together a small program, it nearly always
works. When it doesn't, it generally complains about some numeric
value somewhere. I just stick a "toNumber" in front, et voilà! :D

It uses Rational as representation, temporarily switching to Double when it needs to carry out inexact/irrational computations such as (pi) and (sin). Integral looks reasonable (are those really supposed to be div and mod in defining quotRem, not quot and rem? I'm not sure).

There's no(?) excuse for using GHC extensions... just use (Prelude.)fromRational instead of GHC.Float.fromRat (if using GHC, it will optimize to the same thing, at least if optimizations are on); and remove {-# OPTIONS -fglasgow-exts #-}.

I like the design.

(Have you seen Scheme's (dynamically typed) numeric ladder? It adds a separate, additional concept of being able to tell, from a numeric value, whether it is exact or not - e.g. for this Number implementation, (1 + 1/3) is exact, and (sin pi) isn't, I think.)

Isaac
_______________________________________________
Haskell mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to