Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 快速检查生成器-自定义类型的任意元素_Haskell_Quickcheck - Fatal编程技术网

Haskell 快速检查生成器-自定义类型的任意元素

Haskell 快速检查生成器-自定义类型的任意元素,haskell,quickcheck,Haskell,Quickcheck,我正在尝试为自定义数据类型生成任意大小的元素: newtype ZippList a = ZPL ([a], [a]) deriving (Show) 这就是我得到的: instance Arbitrary a => Arbitrary (ZippList a) where arbitrary = sized zipplist where zipplist n = do firstLength <- choose(0,n) secon

我正在尝试为自定义数据类型生成任意大小的元素:

newtype ZippList a = ZPL ([a], [a])
    deriving (Show)
这就是我得到的:

instance Arbitrary a => Arbitrary (ZippList a) where
arbitrary = sized zipplist where
    zipplist n = do
        firstLength <- choose(0,n)
        secondLength <- n - firstLength
        firstList <- [arbitrary :: Gen a | [1..firstLength]]
        secondList <- [arbitrary :: Gen a | [1..secondLength]]
        return $ ZPL (firstList, secondList)
instance arbitral a=>arbitral(ZippList a)其中
任意=列表大小,其中
zipplist n=do
firstLength这对我很有效

instance Arbitrary a => Arbitrary (ZippList a) where
  arbitrary = sized zipplist where
    zipplist n = do
        firstLength <- choose (0, n)
        let secondLength = n - firstLength
        firstList <- sequence [arbitrary | _ <- [1..firstLength]]
        secondList <- sequence [arbitrary | _ <- [1..secondLength]]
        return $ ZPL (firstList, secondList)
instance arbitral a=>arbitral(ZippList a)其中
任意=列表大小,其中
zipplist n=do

firstLength
sequence[Arbitral |@epsilonhalbe我也喜欢你的方式,但是理解方法在quickstart中似乎是惯用的,因为某些原因,见鬼,我有点忘记了用
_