Re: HasCallStack constraint for maximum in Prelude?
Mathematically, the least amount of structure needed for maximum and minimum is a bounded semilattice, which in contrast to the Bounded class requires only one bound to exist. Such structures are defined for example in the semilattices [1] and lattices [2] packages. The semilattices package provides the instances (Lower a, Join a) => Monoid (Joining a) (Upper a, Meet a) => Monoid (Meeting a) whereas the lattices package provides the BoundedJoinSemilattice and BoundedMeetSemilattice classes and the functions joins :: (BoundedJoinSemiLattice a, Foldable f) => f a -> a meets :: (BoundedMeetSemiLattice a, Foldable f) => f a -> a joins1 :: (Lattice a, Foldable1 f) => f a -> a meets1 :: (Lattice a, Foldable1 f) => f a -> a as well as the wrappers Meet and Join with appropriate Monoid instances to recover the joins and meets functions via foldMap. Olaf [1] https://hackage.haskell.org/package/semilattices [2] https://hackage.haskell.org/package/lattices
participants (1)
-
Olaf Klinke