Reputation: 1575
As a learning exercise I want to write a generator of Data.MeldableHeap
. I patterned it after:
genericArbitrary :: (PriorityQueue pq, Arbitrary a, Ord a) => Gen (pq a)
genericArbitrary = fromList `fmap` listOf arbitrary
My code :
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
import Test.QuickCheck
import Control.Monad (liftM)
import Data.MeldableHeap
genericArbitrary :: (PQ pq, Arbitrary a, Ord a) => Gen (pq a)
genericArbitrary = liftM (foldr (\x acc -> insert x acc) empty) (listOf arbitrary)
but this above gets:
`pq' is applied to too many type arguments
In the type signature for `genericArbitrary':
genericArbitrary :: (PQ pq, Arbitrary a, Ord a) => Gen (pq a)
Please provide guidance.
Update : with your help I got it:
The actual tests could be better, but the point was to learn to use QuickCheck on a non-trivial example. Thanks, H
Upvotes: 1
Views: 678
Reputation: 53901
The difference is that in the code you where looking at, they have a typeclass
class PriorityQueue pq where
insert ...
With a bunch of operations for different priority queues. However, you don't have a typeclass. You have a datatype PQ
which is a concrete type representing one implementation of a priority queue, namely a meldable heap.
Try instead
pqArbitrary :: (Arbitrary a, Ord a) => Gen (PQ a)
pqArbitrary = liftM (foldr (\x acc -> insert x acc) empty) (listOf arbitrary)
pqArbitrary' = foldr insert empty `fmap` listOf arbitrary
Also, I have to comment on the irony of testing one of the handful of packages on Hackage that's proven correct :) (meldable-heap is verified with coq)
Upvotes: 2