• API
• FAQ
• Tools
• Archive
SHARE
TWEET

Untitled

a guest Apr 26th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
2. powerlist [] = [[]]
3. powerlist (x:xs) = [x:sublist | sublist <- powerlist xs] ++ powerlist xs
5. product xs ys = [x | x <- xs, elem x ys]
7. sum xs ys = xs ++ [y | y <- ys, not (elem y xs)]
9. {-
10. a) 6 / (12 / (24 / (8 / 2))) = 3.0
11.   6 / (foldr (/) 2 [12,24,8])
12.   6 / ( 12 / (foldr (/) 2 [24,8]))
13.   6 / ( 12 / (24 / (foldr (/) 2 [8])))
14.   6 / ( 12 / (24 / ( 8 / (foldr (/) 2 []))))
15.   6 / ( 12 / (24 / ( 8 / 2)))
16.   6 / ( 12 / (24 /  4 ))
17.   6 / ( 12 / 6 )
18.   6 / 2
19.   3
20.
21. b) (1 > 2 && (3 > 2 && (5 == 5 && True))) = False
22. c) (max 3 (max 6 (max 12 (max 4 (max 55 (max 11 18)))))) = 55
23. d) (max 3 (max 6 (max 12 (max 4 (max 55 (max 11 81)))))) = 81
24. e) ((((((10 + ((54 + 6) / 2)) / 2) + 4) / 2) + 24) / 2) = 18
25. f) ((((((((54 + 2) / 2) + 4) / 2) + 10) / 2) + 6) / 2) = 9.5
26. g) (((64 / 4) / 2) / 4) = 2
27.   foldl (/) ( 64 / 4) [2, 4]
28.   foldl (/) ( (64 / 4) / 2 ) [4]
29.   foldl (/) ( ((64 / 4) / 2) / 4 ) []
30.   ((16 / 2) / 4)
31.   (8 / 4)
32.   2
33.
34. h) (2*(2*(2*8 + 1) + 2) + 3) = 75
35. -}
37. check x xs = (==0) \$ foldl (\x y -> if x == y then 0 else x) x xs
39. foldlmap f []       = []
40. foldlmap f (x:xs)   = foldl (\x xs -> (f x):xs) [] (x:xs) --- !!!!!
41.
42. foldrmap f []       = []
43. foldrmap f (x:xs)   = foldr (\x xs -> (f x):xs) [] (x:xs)
45. -- a)
46. foldllast (x:xs) = foldl1 (\x y -> y) (x:xs)
47. foldrlast (x:xs) = foldr1 (\x y -> y) (x:xs)
48.
49. -- b)
50. foldlhead (x:xs) = foldl1 (\x y -> x) (x:xs)
51. foldrhead (x:xs) = foldr1 (\x y -> x) (x:xs)
52.
53. -- c)
54. foldlmax (x:xs) = foldl1 (\x y -> max x y) (x:xs)
55. foldrmax (x:xs) = foldr1 (\x y -> max x y) (x:xs)