comparison exercises/src/Exercise_5.hs @ 12:8496af3b866b

add G5.3 and G5.4 definitions
author Markus Kaiser <markus.kaiser@in.tum.de>
date Wed, 14 Nov 2012 19:13:22 +0100
parents a721abd5a135
children 8cc37c82619c
comparison
equal deleted inserted replaced
11:a721abd5a135 12:8496af3b866b
47 47
48 partition_rec :: (a -> Bool) -> [a] -> ([a], [a]) 48 partition_rec :: (a -> Bool) -> [a] -> ([a], [a])
49 partition_rec p xs = undefined 49 partition_rec p xs = undefined
50 50
51 51
52 partition_foldl :: (a -> Bool) -> [a] -> ([a], [a]) 52 partition_foldr :: (a -> Bool) -> [a] -> ([a], [a])
53 partition_foldl p xs = undefined 53 partition_foldr p xs = undefined
54 54
55 55
56 partition_filter :: (a -> Bool) -> [a] -> ([a], [a]) 56 partition_filter :: (a -> Bool) -> [a] -> ([a], [a])
57 partition_filter p xs = undefined 57 partition_filter p xs = undefined
58 58
59 59
60 zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c] 60 zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
61 zipWith' f xs ys = undefined 61 zipWith' f xs ys = undefined
62
63
64
65 {---------------------------------------------------------------------}
66 {- Aufgabe G5.3 -}
67
68 lambda_1 = (\xs -> foldr (++) [] (map (\x -> [x]) xs))
69 lambda_2 = (\gg xx yy -> head (tail (zipWith gg [ xx , xx ] [ yy , yy ])))
70
71
72
73 {---------------------------------------------------------------------}
74 {- Aufgabe G5.4 -}
75
76 zeros :: [Int]
77 zeros = 0 : zeros
78
79
80 length' :: [a] -> Int
81 length' [] = 0
82 length' (_:xs) = 1 + length' xs
83
84
85 h :: Integer -> Integer -> Integer
86 h m n
87 | m == n = 0
88 | m < n = h m (n - 1)
89 | m >= n = h n m + 1
62 90
63 91
64 92
65 {---------------------------------------------------------------------} 93 {---------------------------------------------------------------------}
66 {- Aufgabe H5.1 -} 94 {- Aufgabe H5.1 -}