[Haskell-cafe] Set of reals...?
Keith Wansbrough
Keith.Wansbrough at cl.cam.ac.uk
Fri Oct 29 06:14:44 EDT 2004
[(Double,Double)] is not enough - you need to know if each end is open
or closed. Also note that you will have to use -infinity and +infinity
(-inf and +inf) to model things like the complement of (1.0,2.0).
Which brings me to a question: is there a better way to write -inf and
+inf in Haskell than "-1/0" and "1/0"?
Your data structure should be something like:
data Interval = Interval {
left :: Double,
leftopen :: Bool,
right :: Double,
rightopen :: Bool
}
data Set = Set [Interval]
If you want more efficiency, you probably want a bintree datastructure
(search Google for "quadtree" and "octree", and make the obvious
dimension shift).
--KW 8-)
--
Keith Wansbrough <kw217 at cl.cam.ac.uk>
http://www.cl.cam.ac.uk/users/kw217/
University of Cambridge Computer Laboratory.
More information about the Haskell-Cafe
mailing list