CS计算机代考程序代写 module MyTest (EvensTree(Tip), mkBranch) where

module MyTest (EvensTree(Tip), mkBranch) where

data EvensTree = Tip | Branch EvensTree Int EvensTree
deriving (Eq, Show)

mkBranch :: EvensTree -> Int -> EvensTree -> EvensTree
mkBranch l v r = if v `mod` 2 == 0
then Branch l v r
else error “no, this is not an even number”

replaceNth :: [a] -> Int -> a -> [a]
replaceNth xs i v = take i xs ++ [v] ++ drop (i + 1) xs

{-
powersets!

[] : [[]]
[1] : [[1], []]
[1,2] : [[1,2], [1], [2], []]
[1,2,3] : [[1,2,3], [1,2], [1,3], [2,3], [1], [2], [3], []]

-}

powerSet :: [a] -> [[a]]
powerSet [] = [[]]
powerSet (x:xs) = map ([x] ++) (powerSet xs) ++ powerSet xs

— map (\y -> x : y) (powerSet xs)