我应该填写一些东西undefined
来编译和测试程序。我真的不知道这里的 symdiff 应该做什么,所以我不知道我可以填写什么undefined
。有人可以给我一个提示,我可以插入undefined
什么吗?
顺便说一句,当我想用 ghci 7.6.3 编译代码时出现错误:
Could not find module 'Test.SmallCheck.Series'
我该如何解决?
这是代码:
{-# language FlexibleInstances #-}
{-# language MultiParamTypeClasses #-}
{-# language NoMonomorphismRestriction #-}
module Blueprint where
import Test.SmallCheck
import Test.SmallCheck.Series
data N = Z | S N deriving (Show , Eq)
symdiff :: N -> N -> N
symdiff x y = undefined
-- for testing in ghci: smallCheck 10 spec1
spec1 = \ (x,y) -> symdiff x y == symdiff y x
spec2 = \ (x,y) -> symdiff x (plus x y) == y
plus :: N -> N -> N
plus x y = case x of
Z -> y
S x' -> S (plus x' y)
test :: Bool
test = and
[ null $ failures 10 1000 $ spec1
, null $ failures 10 1000 $ spec2
]
instance Monad m => Serial m N where series = cons0 Z \/ cons1 S
-- | first f failures from t testcases for property p
failures f t p = take f
$ filter ( \ x -> not $ p x )
$ take t
$ do d <- [ 0 .. ] ; list d series
谢谢,这有很大帮助!那这个呢:
symdiff :: N -> N -> N
symdiff x y = case x of
Z -> y
S x' -> case y of
Z -> x
S y' -> ???
这些行是否正确(除了带有???的行,我已经在考虑了)
这适用于最后一行:
S y' -> symdiff x' y'