我应该为undefined填写一些东西,以便编译和测试程序。我不知道这里的符号应该做什么,所以我不知道我能为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'
发布于 2014-05-07 16:33:26
提示出现在小型测试中:
spec1 = \ (x,y) -> symdiff x y == symdiff y x
spec2 = \ (x,y) -> symdiff x (plus x y) == y这意味着symdiff需要满足这两个方程。
symdiff x y == symdiff y x -- shouldn't matter what order (symmetric?)
symdiff x (plus x y) == y -- if they differ by y, that's the answer (difference)这意味着symdiff必须找到这两个参数之间的区别。
您需要将Z看作是零,而S x是x的继承者,即x+1。
好消息是,N只有两种可能性,所以symdiff最多有四个方程
symdiff Z Z =
symdiff Z (S y) =
symdiff (S x) Z =
symdiff (S x) (S y) =想一想你会如何发现
0和0
0和1+y
1+x和0
1+x和1+y
来帮助你。
(您可以简化为较少的情况,但从这四种情况开始。)
现在就好好想一想,如果这还不够,在好好想想之后再暗示一下,评论一下。
https://stackoverflow.com/questions/23523000
复制相似问题