{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wall #-}
module NumHask.Algebra.Ring
( Distributive,
Ring,
StarSemiring (..),
KleeneAlgebra,
InvolutiveRing (..),
two,
)
where
import Data.Int (Int16, Int32, Int64, Int8)
import Data.Word (Word, Word16, Word32, Word64, Word8)
import GHC.Natural (Natural (..))
import NumHask.Algebra.Additive (Additive ((+)), Subtractive)
import NumHask.Algebra.Group (Idempotent)
import NumHask.Algebra.Multiplicative (Multiplicative (..))
import qualified Prelude as P
class
(Additive a, Multiplicative a) =>
Distributive a
instance Distributive P.Double
instance Distributive P.Float
instance Distributive P.Int
instance Distributive P.Integer
instance Distributive Natural
instance Distributive Int8
instance Distributive Int16
instance Distributive Int32
instance Distributive Int64
instance Distributive Word
instance Distributive Word8
instance Distributive Word16
instance Distributive Word32
instance Distributive Word64
instance Distributive P.Bool
instance Distributive b => Distributive (a -> b)
class
(Distributive a, Subtractive a) =>
Ring a
instance
(Distributive a, Subtractive a) =>
Ring a
class (Distributive a) => StarSemiring a where
star :: a -> a
star a
a = a
forall a. Multiplicative a => a
one a -> a -> a
forall a. Additive a => a -> a -> a
+ a -> a
forall a. StarSemiring a => a -> a
plus a
a
plus :: a -> a
plus a
a = a
a a -> a -> a
forall a. Multiplicative a => a -> a -> a
* a -> a
forall a. StarSemiring a => a -> a
star a
a
instance StarSemiring b => StarSemiring (a -> b)
class (StarSemiring a, Idempotent a) => KleeneAlgebra a
instance KleeneAlgebra b => KleeneAlgebra (a -> b)
class (Distributive a) => InvolutiveRing a where
adj :: a -> a
adj a
x = a
x
instance InvolutiveRing P.Double
instance InvolutiveRing P.Float
instance InvolutiveRing P.Integer
instance InvolutiveRing P.Int
instance InvolutiveRing Natural
instance InvolutiveRing Int8
instance InvolutiveRing Int16
instance InvolutiveRing Int32
instance InvolutiveRing Int64
instance InvolutiveRing Word
instance InvolutiveRing Word8
instance InvolutiveRing Word16
instance InvolutiveRing Word32
instance InvolutiveRing Word64
instance InvolutiveRing b => InvolutiveRing (a -> b)
two :: (Multiplicative a, Additive a) => a
two :: a
two = a
forall a. Multiplicative a => a
one a -> a -> a
forall a. Additive a => a -> a -> a
+ a
forall a. Multiplicative a => a
one