Semigroup / Monoid instance
Closed this issue · 3 comments
phadej commented
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
Things to think about:
- We'd incur a
semigroups
dependency intersection
is also a semigroup / monoid
It looks like the the revdeps already depend on semigroups
. I'm leaning towards a newtype for one or both instances.
phadej commented
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
@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.