[Haskell-beginners] Using intersecting ranges to narrow a range yields an "Out of Memory" error

Costello, Roger L. costello at mitre.org
Sun Jul 24 23:26:12 CEST 2011


Hi Folks,

I am creating an Int range by starting with the full range of Int:

let r1  =  [minBound::Int .. maxBound::Int]

Then I restrict the upper bound of the range, e.g.,

let r2  =  r1 `intersect` [minBound::Int .. 10]

Then I restrict the lower bound of the range, e.g.,

let r3  =  r2 `intersect` [0 .. maxBound::Int]

No error thus far.

However, when I try to display r3 I get an "Out of Memory" error.

Why is that?

I created a function that restricts a range using the above approach:

restrict                                  ::  [Int] -> Restriction-> [Int]
restrict r (MinInclusive v)    =   r `intersect` [v .. maxBound::Int]
restrict r (MaxInclusive v)   =   r `intersect` [minBound::Int .. v]

The arguments to "restrict" is a range, r, and an indication of whether the upper bound is to be restricted (MaxInclusive v) or the lower bound is to be restricted (MinInclusive v).

Is there a better way to do this?

What can I do to my restrict function to avoid getting an "Out of Memory" error?

/Roger



More information about the Beginners mailing list