ekmett / intervals

Interval Arithmetic
http://hackage.haskell.org/package/intervals
BSD 2-Clause "Simplified" License
27 stars 13 forks source link

Add union #41

Closed mitchellwrosen closed 7 years ago

mitchellwrosen commented 8 years ago

I've found this useful a couple times, but I'm not sure if it belongs in this library proper.

ekmett commented 8 years ago

This is a bit of a strange operation.

ekmett commented 8 years ago

It isn't a hull, and it isn't an intersection, its an 'if and only if they could overlap then extend to the hull', which doesn't sound very union-y to me.

mitchellwrosen commented 8 years ago

Indeed. I'm using in a [Interval a] -> [Interval a] function that merges a sorted list of intervals (primary lower bound, secondary upper bound), outputting a list of non-overlapping intervals.

That is,

merge [1...5, 6...10] = [1...5, 6...10]
merge [1...5, 5...10] = [1...10]

Anyways, just thought it might be useful upstream. If not, close away.

dmcclean commented 8 years ago

Postgresql's union operator (named +) for range types (their name for what we call interval types, their interval type is something else) operates essentially this way. But it throws an exception in the case of non-overlapping ranges.

I'm not sure I get the example use.

Maybe extend or extendIfPossible, or combineOverlapping or something is a better name?

Or maybe we just want the function that takes a set of intervals and shrinks it by outputting non-overlapping intervals with the same coverage, that certainly seems more useful in general and easier to document? Heck, full blown support for IntervalSets would be nice.

mitchellwrosen commented 8 years ago

Your last paragraph describes the merge function I was trying to convey =) On Jun 13, 2016 4:50 PM, "Douglas McClean" notifications@github.com wrote:

Postgresql's union operator (named +) for range types (their name for what we call interval types, their interval type is something else) operates essentially this way. But it throws an exception in the case of non-overlapping ranges.

I'm not sure I get the example use.

Maybe extend or extendIfPossible, or combineOverlapping or something is a better name?

Or maybe we just want the function that takes a set of intervals and shrinks it by outputting non-overlapping intervals with the same coverage, that certainly seems more useful in general and easier to document? Heck, full blown support for IntervalSets would be nice.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ekmett/intervals/pull/41#issuecomment-225704162, or mute the thread https://github.com/notifications/unsubscribe/ABBlppA3rUa9jMgHMqYfsborgMNzXo7_ks5qLcJ8gaJpZM4I0o66 .

ekmett commented 8 years ago

A full-on module for IntervalSets would be nice to have and could subsume this usecase.

dmcclean commented 8 years ago

See https://hackage.haskell.org/package/IntervalMap for some existing work.

ekmett commented 7 years ago

I'm going to go with the close option, just because this has been lingering a long time and the operation still makes me uncomfortable.