Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there Bounded (Maybe a) for un-Bounded a?

Tags:

haskell

I have a Foldable of Integers which are unbounded and thus I cannot apply a Max fold to it.

Would it make sense to define Max instance of Nothing when a value does not exist? There is Ord a => Semigroup (Max a) but I cannot find Max instance for (Ord a) => Option a.

See foldReduce for more context.

like image 662
sevo Avatar asked May 07 '18 20:05

sevo


1 Answers

The monoid-extras package offers Data.Monoid.Inf for one-sided bounds. The extended-reals package offers Data.ExtendedReal, which is sometimes more convenient if you want to add both bounds in one shot without privileging one or the other's Monoid instance or want a fresh Bounded instance that doesn't rely on the underlying type being Bounded.

like image 121
Daniel Wagner Avatar answered Sep 18 '22 01:09

Daniel Wagner