문제

I am using the Data.List.Vector in my program, and now I would like to use quickCheck for it. However, there is no instance for that. Since there already is an arbitrary for [Double], I thought I could do something like

instance Arbitrary V.Vector Double where
    arbitrary = V.fromList (arbitrary :: [Double])

alas, GHC does not like this at all:

`Arbitrary' is applied to too many type arguments
In the instance declaration for `Arbitrary V.Vector Double'

I guess I could also just make a bunch of properties that take in a [Double] and uses V.fromList, but that seems tedious.

도움이 되었습니까?

해결책

Your problem is that you need to parenthesize it, like instance Arbitrary (V.Vector Double), etc. But there's a better way to do it:

instance (Arbitrary a) => Arbitrary (V.Vector a) where
    arbitrary = fmap V.fromList arbitrary

Note that you need the fmap because arbitrary is a value of type Gen a, and so in order to go from Gen [a] to Gen (V.Vector a) you need to lift V.fromList into Gen, which you can do since it's a functor.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top