I am supposed to fill in something for undefined
to get the program compiled and test it. I don't really know what symdiff here is supposed to do, so I don't know what I can fill in for undefined
. Can someone give me a hint, what I can insert into undefined
?
By the way, when I want to compile the code with ghci 7.6.3 I get an error:
Could not find module 'Test.SmallCheck.Series'
how can I fix that?
Here is the code:
{-# 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
thanks, that helped a lot! what about this:
symdiff :: N -> N -> N
symdiff x y = case x of
Z -> y
S x' -> case y of
Z -> x
S y' -> ???
Are these lines correct (except the line with ???, I am thinking about it at already)
This works for the last line:
S y' -> symdiff x' y'