@@ -8,7 +8,7 @@ import Test.ChasingBottoms.IsBottom
88import Test.Framework (Test , defaultMain , testGroup )
99import Test.Framework.Providers.QuickCheck2 (testProperty )
1010import Test.QuickCheck (Arbitrary (arbitrary ), CoArbitrary , Property , (===) , (.&&.) )
11- import Test.QuickCheck.Function
11+ import Test.QuickCheck.Function ( Fun ( Fun ), Function ( function ), functionMap )
1212import Test.QuickCheck.Poly (A )
1313import Data.Maybe (fromMaybe , isJust )
1414import Control.Arrow (second )
@@ -27,12 +27,12 @@ import qualified Data.HashMap.Strict as HM
2727newtype Key = K { unK :: Int }
2828 deriving (Arbitrary , CoArbitrary , Eq , Ord , Show )
2929
30- instance Function Key where
31- function = functionMap unK K
32-
3330instance Hashable Key where
3431 hashWithSalt salt k = hashWithSalt salt (unK k) `mod` 20
3532
33+ instance Function Key where
34+ function = functionMap unK K
35+
3636instance (Arbitrary k , Arbitrary v , Eq k , Hashable k ) =>
3737 Arbitrary (HashMap k v ) where
3838 arbitrary = HM. fromList `fmap` arbitrary
@@ -43,6 +43,16 @@ instance Show (Int -> Int) where
4343instance Show (Int -> Int -> Int ) where
4444 show _ = " <function>"
4545
46+ -- | Extracts the value of a ternary function.
47+ -- Copied from Test.QuickCheck.Function.applyFun3
48+ applyFun2 :: Fun (a , b ) c -> (a -> b -> c )
49+ applyFun2 (Fun _ f) a b = f (a, b)
50+
51+ -- | Extracts the value of a ternary function.
52+ -- Copied from Test.QuickCheck.Function.applyFun3
53+ applyFun3 :: Fun (a , b , c ) d -> (a -> b -> c -> d )
54+ applyFun3 (Fun _ f) a b c = f (a, b, c)
55+
4656------------------------------------------------------------------------
4757-- * Properties
4858
@@ -76,18 +86,13 @@ pInsertValueStrict k m = isBottom $ HM.insert k bottom m
7686
7787pInsertWithKeyStrict :: Fun (Int , Int ) Int -> Int -> HashMap Key Int -> Bool
7888pInsertWithKeyStrict f v m =
79- isBottom $ HM. insertWith (curry . apply $ f) bottom v m
89+ isBottom $ HM. insertWith (applyFun2 f) bottom v m
8090
8191pInsertWithValueStrict :: Fun (Int , Int ) Int -> Key -> Int -> HashMap Key Int
8292 -> Bool
8393pInsertWithValueStrict f k v m
8494 | HM. member k m = isBottom $ HM. insertWith (const2 bottom) k v m
85- | otherwise = isBottom $ HM. insertWith (curry . apply $ f) k bottom m
86-
87- -- | Extracts the value of a ternary function.
88- -- Copied from Test.QuickCheck.Function.applyFun3
89- applyFun3 :: Fun (a , b , c ) d -> (a -> b -> c -> d )
90- applyFun3 (Fun _ f) a b c = f (a, b, c)
95+ | otherwise = isBottom $ HM. insertWith (applyFun2 f) k bottom m
9196
9297pInsertWithKeyKeyStrict :: Fun (Key , Int , Int ) Int -> Int -> HashMap Key Int -> Bool
9398pInsertWithKeyKeyStrict f v m =
@@ -149,11 +154,11 @@ pFromListWithValueResultStrict lst comb_lazy calc_good_raw
149154 calc_good Nothing y@ (Just _) = cgr Nothing Nothing || cgr Nothing y
150155 calc_good x@ (Just _) Nothing = cgr Nothing Nothing || cgr x Nothing
151156 calc_good x y = cgr Nothing Nothing || cgr Nothing y || cgr x Nothing || cgr x y
152- cgr = curry $ apply calc_good_raw
157+ cgr = applyFun2 calc_good_raw
153158
154159 -- The Maybe A -> Maybe A -> Maybe A that we're after, representing a
155160 -- potentially less total function than comb_lazy
156- comb x y = apply comb_lazy (x, y) <$ guard (calc_good x y)
161+ comb x y = applyFun2 comb_lazy x y <$ guard (calc_good x y)
157162
158163 -- What we get out of the conversion using fromListWith
159164 real_map = HM. fromListWith real_comb real_list
0 commit comments