{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE KindSignatures #-}
module Data.JoinSemilattice.Class.Abs where
import Data.Hashable (Hashable)
import Data.JoinSemilattice.Class.Merge (Merge)
import Data.JoinSemilattice.Defined (Defined)
import Data.JoinSemilattice.Intersect (Intersect)
import qualified Data.JoinSemilattice.Intersect as Intersect
import Data.Kind (Type)
class Merge x => AbsR (x :: Type) where
absR :: ( x, x ) -> ( x, x )
default absR :: Num x => ( x, x ) -> ( x, x )
absR ( x
x, x
_ ) = ( x
forall a. Monoid a => a
mempty, x -> x
forall a. Num a => a -> a
abs x
x )
instance (Eq x, Num x) => AbsR (Defined x)
instance (Bounded x, Enum x, Ord x, Hashable x, Num x)
=> AbsR (Intersect x) where
absR :: (Intersect x, Intersect x) -> (Intersect x, Intersect x)
absR ( Intersect x
x, Intersect x
y ) = ( Intersect x -> Intersect x -> Intersect x
forall x.
Intersectable x =>
Intersect x -> Intersect x -> Intersect x
Intersect.union Intersect x
y (Intersect x -> Intersect x
forall a. Num a => a -> a
negate Intersect x
y), Intersect x -> Intersect x
forall a. Num a => a -> a
abs Intersect x
x )