Advertisement
KillianMills

Solutions.hs

Nov 17th, 2014
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --QUESTION 1--
  2. nums7 :: [Int]
  3. nums7 = [n | n <-[7,14..200],mod n 2 ==0]
  4.  
  5. --QUESTION 2--
  6. listNums :: Int -> Int -> [Int]
  7. listNums a b = [a..b]
  8.    
  9. --QUESTION 3-- 
  10. diff :: (Eq a) => [a] -> [a] -> [a] -- all of type a, any type
  11. diff a b = [a | a <- a, not (elem a b)]
  12.  
  13. --QUESTION 4--
  14. data BinTree t = Empty | Root t (BinTree t) (BinTree t)
  15.                 deriving (Eq, Ord, Show)
  16.        
  17. --QUESTION 5--
  18. preorder :: BinTree a -> [a]
  19. preorder Empty = []
  20. preorder (Root x l r) = preorder l ++ preorder r ++ [x]
  21.  
  22.  
  23. --EXTRAS--
  24. union :: (Eq a) => [a] -> [a] -> [a]
  25. union a b = [ a | a <- a, not ( elem a b)] ++ [a | a <-b]
  26.  
  27. intersection ::(Eq a)=> [a] -> [a] -> [a]
  28. intersection a b = [ a | a <- a, (elem a b )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement