-2

quickCheckResult 只接受something -> Bool,然后我模仿一些例子,通过

[Colour] -> Bool

[颜色]括号的作用是什么?为什么不Colour -> Bool呢?如何将任意实例传递给 quickCheckResult?

data Colour = Green | Blue
instance Arbitrary Colour where
   arbitrary = oneof [return Green, return Blue]

main = quickCheckResult ((\s -> s == s) :: [Colour] -> Bool)

[更新]我的目标是以下可以运行

import Test.QuickCheck.Function
import Test.QuickCheck.Gen
import Test.QuickCheck
import Test.QuickCheck.Function
import Test.QuickCheck.Arbitrary
import Test.QuickCheck.Property
import Test.QuickCheck.Test

prop1 f g x = (g.f) x == (f.g) x where types = [f, g] :: [Int->Int]

instance CoArbitrary ex where
  coarbitrary f g = prop1 (variant 0 f) (variant 0 g)

main = quickCheck prop1

test5.hs:11:10:
    Illegal instance declaration for `CoArbitrary ex'
      (All instance types must be of the form (T a1 ... an)
       where a1 ... an are *distinct type variables*,
       and each type variable appears at most once in the instance head.
       Use -XFlexibleInstances if you want to disable this.)
    In the instance declaration for `CoArbitrary ex'

3.QuickCheck.Function使用方法(更新)

prop :: Fun Fun Integer -> Bool
let prop (Fun _ f) (Fun _ g) = (g.f) x == (f.g) x
quickCheck prop

解析错误(可能不正确的缩进)

4

2 回答 2

2

好的,您可能应该将其拆分为单独的问题。

带有 [Color] 的东西意味着该函数接受 Color 列表作为参数。

任意函数已由 quickCheck 执行。无需传入实例。

3 的问题在于您的 let 绑定。Let 绑定用于将新绑定引入本地范围,但是,您在本地范围内定义它,因此您不使用 let。

import Test.QuickCheck.Function
prop :: Fun Fun Integer -> Bool
prop (Fun _ f) (Fun _ g) = (g.f) x == (f.g) x 
quickCheck prop
于 2011-11-18T08:11:47.423 回答
1

类型[Colour]是一个列表Colour

于 2011-11-18T08:07:37.540 回答