msakai / data-interval

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

IntegerInterval: add memberCount #44

Closed ncfavier closed 11 months ago

ncfavier commented 11 months ago

Returns the number of integers that lie within an integer interval.

This is different from the width and cannot simply be computed as (+ 1) . width because of the null interval.

Addresses https://github.com/msakai/data-interval/issues/39

EDIT: I initially named this magnitude because I misunderstood what Numeric.Interval.magnitude does. Feel free to suggest a better name.

Bodigrim commented 11 months ago

Shall we make it total, returning Maybe Integer?

ncfavier commented 11 months ago

In that case we might as well return Extended Integer, so that the memberCount of an unbounded interval is PosInf?

Bodigrim commented 11 months ago

Imagine yourself on the consuming end, where you have to pattern match on the output of memberCount. What would you do for NegInf? Throw error "this should never happen"? I'd prefer to receive Maybe.

Bodigrim commented 11 months ago

Thanks!

ncfavier commented 11 months ago

Thanks! A release including this change (and my last one from last year) would be appreciated.

Bodigrim commented 10 months ago

Done: https://hackage.haskell.org/package/data-interval-2.1.2