Question

As a learning exercise I want to write a generator of Data.MeldableHeap. I patterned it after:

https://gitorious.org/aocapq/aocapq/source/7f24bb1571b3bd89ada668ea81c37ccdeb825498:src/PriorityQueue/QuickCheck.hs :

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:

https://github.com/haroldcarr/learn-haskell-coq-ml-etc/blob/master/haskell/course/coursera-fp-odersky-but-in-haskell/FRP01QuickCheck.hs

The actual tests could be better, but the point was to learn to use QuickCheck on a non-trivial example. Thanks, H

Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top