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
firstLengthsequence[Arbitral |@epsilonhalbe我也喜欢你的方式,但是理解方法在quickstart中似乎是惯用的,因为某些原因,见鬼,我有点忘记了用_