我有这个功能foo
:
foo :: [a] -> (a -> b) -> [b]
foo [] f = []
foo (x:xs) f = foo xs f
以及它必须满足的以下两个属性:
prop_1 :: [Int] -> Bool
prop_1 xs = foo xs id == xs
prop_2 :: [Int] -> (Int -> Int) -> (Int -> Int) -> Bool
prop_2 xs f g = foo (foo xs f) g == foo xs (g . f)
当我尝试使用 quickCheck 测试该功能时,我收到以下错误:
Ambiguous type variable 't0' arising from a use of '=='
prevents the constraint '(Eq t0)' from being solved.
Probable fix: use a type annotation to specify what 't0' should be.
These potential instances exist:
instance (Eq a, Eq b) => Eq (Either a b)
-- Defined in 'Data.Either'
instance Eq GeneralCategory -- Defined in 'GHC.Unicode'
instance Eq Ordering -- Defined in 'ghc-prim-0.5.0.0:GHC.Classes'
...plus 24 others
...plus 107 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
In the expression: foo (foo xs f) g == foo xs (g . f)
In an equation for 'prop_2':
prop_2 xs f g = foo (foo xs f) g == foo xs (g . f)
Failed, modules loaded: none.
我不确定为什么会收到此错误以及如何解决它。任何见解都值得赞赏。