function - 编译器中止测试
问题描述
我试图在函数中指定变量,但没有帮助。
功能:
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
推荐阅读
- python-3.x - 将数据框导出到包含列表的列的 csv
- react-native - react-native 中的参数路由
- c# - SSIS 脚本组件 Parallel.ForEach
- javascript - 画布比例还可以翻译形状意外可能的枢轴锚相关问题
- php - win10如何重新加载php.ini?
- c++ - 如果 operator new 是一个函数,那么为什么它在类中重载时被定义为 operator
- java - 单击菜单栏项后尝试开始新的井字游戏
- sql-server - 让 XML 输入 SQL Server 表
- typo3 - EXT:Form TYPO3 表单装订器设置不起作用
- prolog - 使用 read/1 时出现意外的 end_of_file