{-# Language ConstraintKinds #-}
{-# LANGUAGE Safe #-}
module Data.Dioid where
import safe Data.Word
import safe Data.Connection
import safe Data.Connection.Word
import safe Data.Connection.Yoneda
import safe Data.Semiring
import safe Data.Prd
import safe Numeric.Natural
import safe GHC.Real
import safe Prelude hiding (Num(..))
import safe qualified Prelude as N
type Positive = Ratio Natural
class (Prd r, Semiring r) => Dioid r where
fromNatural :: Natural -> r
instance Dioid () where
fromNatural _ = ()
instance Dioid Bool where
fromNatural 0 = False
fromNatural _ = True
instance Dioid Word8 where
fromNatural = connr w08nat
instance Dioid Word16 where
fromNatural = connr w16nat
instance Dioid Word32 where
fromNatural = connr w32nat
instance Dioid Word64 where
fromNatural = connr w64nat
instance Dioid Natural where
fromNatural = id
instance Dioid Positive where
fromNatural x = x :% sunit
instance (Monoid a, Monoid b, Dioid a, Dioid b) => Dioid (a, b) where
fromNatural x = (fromNatural x, fromNatural x)
instance (Monoid a, Monoid b, Monoid c, Dioid a, Dioid b, Dioid c) => Dioid (a, b, c) where
fromNatural x = (fromNatural x, fromNatural x, fromNatural x)