{-# 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, _ ) = ( mempty, abs x )
instance (Eq x, Num x) => AbsR (Defined x)
instance (Bounded x, Enum x, Eq x, Hashable x, Num x)
=> AbsR (Intersect x) where
absR ( x, y ) = ( Intersect.union y (negate y), abs x )