-
Notifications
You must be signed in to change notification settings - Fork 0
/
MonoidTest.hs
42 lines (32 loc) · 1003 Bytes
/
MonoidTest.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Test.QuickCheck
instance Monoid Int where
mappend = (*)
mempty = 1
mnLawAp :: (Monoid a, Eq a) => a -> a -> a -> Bool
mnLawAp x y z = (x `mappend` y) `mappend` z == x `mappend` (y `mappend` z)
mnLawEm :: (Monoid a, Eq a) => a -> Bool
mnLawEm x =
let left = mempty `mappend` x
right = x `mappend` mempty
in left == right && right == x
mnTestApInt :: IO ()
mnTestApInt = let mnLawAp' = mnLawAp :: Int -> Int -> Int -> Bool
in quickCheck mnLawAp'
mnTestEmInt :: IO ()
mnTestEmInt = let mnLawEm' = mnLawEm :: Int -> Bool
in quickCheck mnLawEm'
--instance Monoid [a] where
-- mappend = (++)
-- mempty = []
mnTestApList :: IO ()
mnTestApList = let mnLawAp' = mnLawAp :: [Float] -> [Float] -> [Float] -> Bool
in quickCheck mnLawAp'
mnTestEmList :: IO ()
mnTestEmList = let mnLawEm' = mnLawEm :: [Float] -> Bool
in quickCheck mnLawEm'
main :: IO ()
main = do
mnTestApInt
mnTestEmInt
mnTestApList
mnTestEmList