-2

quickCheckResult only accept something -> Bool, then i mimic some example, pass

[Colour] -> Bool

what is function of the bracket of [Colour]? why not Colour -> Bool? How to pass Arbitrary instance to quickCheckResult?

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

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

[Updated] My goal is the following can run

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.How to use QuickCheck.Function (Updated)

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

parse error (possibly incorrect indentation)

M-Askman
  • 400
  • 4
  • 17

2 Answers2

2

Ok, you should probably split this up into separate questions.

The thing with [Colour] means that the function accepts a list of Colour as a parameter.

The arbitrary function is executed by quickCheck already. There is no need to pass in the instance.

The problem with 3 is with your let binding. Let bindings are used to introduce new bindings into a local scope, however, you are defining this in local scope so you do not use let.

import Test.QuickCheck.Function
prop :: Fun Fun Integer -> Bool
prop (Fun _ f) (Fun _ g) = (g.f) x == (f.g) x 
quickCheck prop
Andrew Marsh
  • 2,032
  • 15
  • 14
  • Someone told me to implement CoArbitrary first if want to generate function, then i find that CoArbitrary is in Arbitrary – M-Askman Nov 18 '11 at 08:39
  • 1
    Only in older versions of QuickCheck. In newer versions arbitrary and coarbitrary are in different type classes. You don't need both Arbitrary and CoArbitrary implemented. Only one of them is enough. – nponeccop Nov 18 '11 at 08:43
  • i get it, instance CoArbitrary XXX where coarbitrary XXXX – M-Askman Nov 18 '11 at 09:11
1

The type [Colour] is a list of Colour.

Landei
  • 54,104
  • 13
  • 100
  • 195