[Haskell-cafe] Set of reals...?

Arthur van Leeuwen arthurvl at cs.uu.nl
Wed Oct 27 05:07:03 EDT 2004

On Wed, Oct 27, 2004 at 04:56:26PM +0900, Stijn De Saeger wrote:
> Hi all, 

> I'm new to this list, as well as to haskell, so this question probably
> has "newbie" written all over it.

Not really.

> I'm thinking of a way to represent a set of reals, say the reals
> between 0.0 and 1.0.  Right now I am just using a pair of Float to
> represent the lower and upper bounds of the set, but i have this dark
> throbbing feeling that there should be a more haskellish way to do
> this, using laziness.
> List comprehensions are out it seems, because they increment with
> integer steps... (obviously). In other words,  0.5 `inSet` (Set
> [0.0..1.0])   returns False.

Yes. That is because lists are either finite or countable, whereas any
interval of the reals is uncountable. Not all is lost however.

> I'm sure someone must have hit this problem before me and found a way
> around it. any suggestions greatly appreciated,

Well, there have been multiple forays into exact real arithmetic, with
implementations in Haskell. One that may well be of use to your problem
is David Plume's calculator for exact real number computation. Google
for it, and for `interval arithmetic'.

Doei, Arthur.

  /\    / |       arthurvl at cs.uu.nl       | Work like you don't need the money
 /__\  /  | A friend is someone with whom | Love like you have never been hurt
/    \/__ | you can dare to be yourself   | Dance like there's nobody watching

More information about the Haskell-Cafe mailing list