Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monoid instance doesn't obey the concatenation law #23

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion slist.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ test-suite slist-test
main-is: Spec.hs

build-depends: slist
, hedgehog
, hedgehog-classes

ghc-options: -threaded
-rtsopts
Expand All @@ -82,4 +84,4 @@ test-suite slist-doctest
build-depends: doctest
, Glob

ghc-options: -threaded
ghc-options: -threaded
2 changes: 1 addition & 1 deletion src/Slist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ instance Monoid (Slist a) where
where
-- foldr :: (a -> ([a], Size) -> ([a], Size)) -> ([a], Size) -> [Slist a] -> ([a], Size)
f :: Slist a -> ([a], Size) -> ([a], Size)
f (Slist l s) (xL, !xS) = (xL ++ l, s + xS)
f (Slist l s) (xL, !xS) = (l ++ xL, s + xS)
{-# INLINE mconcat #-}

instance Functor Slist where
Expand Down
25 changes: 24 additions & 1 deletion test/Spec.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
module Main (main) where

import Slist as SL
import Hedgehog
import Hedgehog.Main (defaultMain)
import Hedgehog.Classes
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range

main :: IO ()
main = putStrLn ("Test suite not yet implemented" :: String)
main = defaultMain $
lawsCheck <$>
[ functorLaws genFiniteSlist
, applicativeLaws genFiniteSlist
, monadLaws genFiniteSlist
, foldableLaws genFiniteSlist
, traversableLaws genFiniteSlist
, alternativeLaws genFiniteSlist
, semigroupLaws (genFiniteSlist genInt)
, monoidLaws (genFiniteSlist genInt)
]

genInt :: Gen Int
genInt = Gen.int (Range.linear 0 100)

genFiniteSlist :: Gen a -> Gen (Slist a)
genFiniteSlist gen = slist <$> Gen.list (Range.linear 0 100) gen