我试过在函数中指定变量,但没用。
功能:
prop_unzip_check :: forall a b. Ord a => [(a,b)] -> Bool
prop_unzip_check xs = length (unzip (xs::[(a,b)])) >= 0
prop_merge_check :: forall a. Ord a => [a] -> [a] -> Bool
prop_merge_check xs ys = length (merge (xs::[a]) (ys::[a]))
== length (sort ((xs::[a]) ++ (ys::[a])))
编译后我收到这个令人困惑的错误:
> Test property "prop_merge_check" ... aborted.
Reason: Ambiguous type variable `a0' arising from a use of `quickCheckBool'
prevents the constraint `(Arbitrary a0)' from being solved.
Probable fix: use a type annotation to specify what `a0' should be.
These potential instances exist:
instance Arbitrary QCGen -- Defined in `Test.QuickCheck.Arbitrary'
instance Arbitrary (a b c) => Arbitrary (WrappedArrow a b c)
-- Defined in `Test.QuickCheck.Arbitrary'
instance Arbitrary (m a) => Arbitrary (WrappedMonad m a)
-- Defined in `Test.QuickCheck.Arbitrary'
...plus 80 others
(use -fprint-potential-instances to see them all)
Ambiguous type variable `a0' arising from a use of `prop_merge_check'
prevents the constraint `(Ord a0)' from being solved.
Probable fix: use a type annotation to specify what `a0' should be.
These potential instances exist:
instance Ord (Encoding' a)
-- Defined in `Data.Aeson.Encoding.Internal'
instance Ord DotNetTime -- Defined in `Data.Aeson.Types.Internal'
instance Ord JSONPathElement
-- Defined in `Data.Aeson.Types.Internal'
...plus 310 others
(use -fprint-potential-instances to see them all)
最佳答案
通过将某些函数定义为 Int 而不是任何类型的函数 'a' 来解决问题。
> prop_unzip_check :: [(Int,Int)] -> Bool
> prop_unzip_check xs = length (unzip (xs::[(Int,Int)])) >= 0
关于function - 编译器中止测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59023293/