packages feed

semiring-num 0.1.0.5 → 0.1.0.6

raw patch · 4 files changed

+20/−7 lines, 4 files

Files

semiring-num.cabal view
@@ -1,5 +1,5 @@ name:                semiring-num-version:             0.1.0.5+version:             0.1.0.6 synopsis:            Basic semiring class and instances description:         Adds a basic semiring class homepage:            https://github.com/oisdk/semiring-num
src/Data/Semiring.hs view
@@ -71,9 +71,7 @@ -- * @a '<.>' (b '<+>' c) = (a '<.>' b) '<+>' (a '<.>' c)@ -- * @(a '<+>' b) '<.>' c = (a '<.>' c) '<+>' (b '<.>' c)@ ----- Another useful law, annihilation, may be deduced from the axioms--- above:---+-- == Annihilation -- * @'zero' '<.>' a = a '<.>' 'zero' = 'zero'@ class Semiring a where   -- | The identity of '<+>'.
src/Data/Semiring/Free.hs view
@@ -4,6 +4,7 @@ {-# LANGUAGE DeriveTraversable          #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} +-- | The Free semiring. module Data.Semiring.Free   ( Free(..)   , liftFree
src/Test/Semiring.hs view
@@ -16,6 +16,7 @@   , mulDistribR   , plusId   , mulId+  , annihilate   , semiringLaws   ) where @@ -88,7 +89,7 @@     , "(x <+> y) <.> z = " ++ show l     , "x <.> z <+> y <.> z = " ++ show r ] --- | Additive identity+-- | Additive identity. plusId :: (Eq a, Semiring a, Show a) => a -> Property plusId x = counterexample s (l == x && r ==x) where   l = x <+> zero@@ -100,7 +101,7 @@     , "x <+> zero = " ++ show l     , "zero <+> x = " ++ show r ] --- | Multiplicative identity+-- | Multiplicative identity. mulId :: (Eq a, Semiring a, Show a) => a -> Property mulId x = counterexample s (l == x && r ==x) where   l = x <.> one@@ -112,6 +113,18 @@     , "x <.> one = " ++ show l     , "one <.> x = " ++ show r ] +-- | Annihilation of '<.>' by 'zero'.+annihilate :: (Eq a, Semiring a, Show a) => a -> Property+annihilate x = counterexample s (l == zero && r == zero) where+  l = x <.> zero+  r = zero <.> x+  s = unlines+    [ "Testing annihilation of <.> by zero."+    , "Law: x <.> zero = zero <.> x = zero"+    , "x = " ++ show x+    , "x <.> zero = " ++ show l+    , "zero <.> x = " ++ show r ]+ -- | A property for all laws of 'Semiring'. semiringLaws :: (Eq a, Semiring a, Show a, Arbitrary a) => Proxy a -> Property semiringLaws (_ :: Proxy a) = conjoin@@ -121,4 +134,5 @@   , property (mulDistribL :: a -> a -> a -> Property)   , property (mulDistribR :: a -> a -> a -> Property)   , property (plusId      ::           a -> Property)-  , property (mulId       ::           a -> Property)]+  , property (mulId       ::           a -> Property)+  , property (annihilate  ::           a -> Property)]