作为一个学习练习,我想编写一个Data.MeldableHeap
. 我在以下之后对其进行了图案化:
genericArbitrary :: (PriorityQueue pq, Arbitrary a, Ord a) => Gen (pq a)
genericArbitrary = fromList `fmap` listOf arbitrary
我的代码:
{-# 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)
但这上面得到:
`pq' is applied to too many type arguments
In the type signature for `genericArbitrary':
genericArbitrary :: (PQ pq, Arbitrary a, Ord a) => Gen (pq a)
请提供指导。
更新:在您的帮助下,我得到了它:
实际测试可能会更好,但重点是要学会在一个重要的例子上使用 QuickCheck。谢谢,