ekmett / intervals

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

Semigroup / Monoid instance #39

Closed phadej closed 4 years ago

phadej commented 8 years ago

Does it make sense to have:

instance Ord a => Semigroup (Interval a) where
  (<>) = hull

instance Ord => Monoid (Interval a) wherre
  mempty = empty
  mappend = (<>)

I could make a PR, if these instances are OK

bergey commented 8 years ago

Things to think about:

It looks like the the revdeps already depend on semigroups. I'm leaning towards a newtype for one or both instances.

phadej commented 8 years ago

intersection is a partial function for non-empty variant, thus I'd prefer Semigroup for it. The newtype for normal variant could be useful indeed: newtype Intersection a = Intersection (Interval a) with mempty = Intersection whole ?

Icelandjack commented 7 years ago

@bergey Data.Semigroup is now in base if that matters,

I was hoping to use this for a similar purpose to data Interval = Between Time Time from Constructing Applicative Functors.