msakai / data-interval

Interval datatype, interval arithmetic, and interval-based containers for Haskell
Other
21 stars 9 forks source link

relate (0 <..< 1) (0 <=..<= 1) should be During #29

Closed Bodigrim closed 3 years ago

Bodigrim commented 3 years ago
> relate (0 <..< 1) (0 <=..<= 1)
Starts

My understanding is that this should return During instead. CC @marcosh

marcosh commented 3 years ago

I think you are right, This week I'm on vacation. Next week I'll take a look at it

marcosh commented 3 years ago

@bodigrim the issue is due to how we currently compare the boundaries of the intervals (using lowerBound and upperBound). This should be fixed using lowerBound' and upperBound' but it actually isn't because relate (NegInf <..< PosInf) (NegInf <=..<= PosInf) == Equal.

I suspect the most elegant solution would be to introduce a new datatype to represent the boundaries of an interval. Instead of using (Extended r, Bounday) it would be nice to have

data IntervalBoundary
    = NegInf
    | PosInf
    | Finite r Boundary

This way we could avoid issues comparing (NegInf, Open) and (NegInf, Closed).

What do you say?

Bodigrim commented 3 years ago

@marcosh I'm a bit reluctant to introduce an intermediary type. Could we possibly express relate directly by pattern-matching on Interval constructors?

https://github.com/msakai/data-interval/blob/2755db4543de8c61a1bfe881f42085109114db7f/src/Data/Interval/Internal.hs#L44-L57