packages feed

semiring-num 0.1.0.4 → 0.1.0.5

raw patch · 3 files changed

+19/−2 lines, 3 files

Files

semiring-num.cabal view
@@ -1,5 +1,5 @@ name:                semiring-num-version:             0.1.0.4+version:             0.1.0.5 synopsis:            Basic semiring class and instances description:         Adds a basic semiring class homepage:            https://github.com/oisdk/semiring-num
src/Data/Semiring.hs view
@@ -126,6 +126,20 @@   zero = Set.empty   one = Set.singleton mempty +-- | A polynomial in /x/ can be defined as a list of its coefficients,+-- where the /i/th element is the coefficient of /x^i/. This is the+-- semiring for such a list. Adapted from <https://pdfs.semanticscholar.org/702d/348c32133997e992db362a19697d5607ab32.pdf here>.+instance Semiring a => Semiring [a] where+  one = [one]+  zero = []+  [] <+> ys = ys+  xs <+> [] = xs+  (x:xs) <+> (y:ys) = (x <+> y) : (xs <+> ys)+  [] <.> _ = []+  _ <.> [] = []+  (x:xs) <.> (y:ys) =+    (x <.> y) : (map (x <.>) ys <+> map (<.> y) xs <+> (xs <.> ys))+ ------------------------------------------------------------------------ -- Addition and multiplication newtypes ------------------------------------------------------------------------
test/Spec.hs view
@@ -12,10 +12,13 @@ import           Test.QuickCheck import           Test.Semiring +smallCheck :: Testable prop => prop -> IO ()+smallCheck = quickCheckWith (stdArgs { maxSuccess = 40, maxSize = 30})  main :: IO () main = do-  quickCheckWith (stdArgs { maxSuccess = 40, maxSize = 30} ) (semiringLaws (Proxy :: Proxy (Free Word8)))+  smallCheck (semiringLaws (Proxy :: Proxy (Free Word8)))+  quickCheck (semiringLaws (Proxy :: Proxy [Integer]))   quickCheck (semiringLaws (Proxy :: Proxy Integer))   quickCheck (semiringLaws (Proxy :: Proxy Bool))   quickCheck (semiringLaws (Proxy :: Proxy (Add Integer)))