如何解决使用 QuickCheck 类库检查函子定律
例如,我想检查函子定律:
instance Functor Stream where
fmap f (x :> xs) = (f x) :> fmap f xs
流在哪里
data Stream a = a :> Stream a
我使用 QuickCheck.Classes (http://hackage.haskell.org/package/quickcheck-classes) 来检查法律,但我遇到了一些问题。当我尝试运行
lawsCheck (functorLaws (Proxy :: Proxy (Stream Int)))
我得到以下信息:
* Couldn't match kind `*' with `* -> *'
When matching types
proxy0 :: (* -> *) -> *
Proxy :: * -> *
Expected: proxy0 f0
Actual: Proxy (Stream Int)
* In the first argument of `functorLaws',namely
`(Proxy :: Proxy (Stream Int))'
In the first argument of `lawsCheck',namely
`(functorLaws (Proxy :: Proxy (Stream Int)))'
In the expression:
lawsCheck (functorLaws (Proxy :: Proxy (Stream Int)))
什么是“proxy0 f0”?有什么办法可以解决这个错误吗?我不明白为什么这段代码没有被执行。
解决方法
正如@leftaroundabout 评论的那样,functorLaws
使用 unapplied 函子,种类为 * -> *
。您的代码的正确版本是:
lawsCheck (functorLaws (Proxy :: Proxy Stream))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。