added "my"
parent
7d5391dae7
commit
725251dc57
|
@ -1,22 +1,22 @@
|
|||
-- Aufgabe: Implementiere die rekursive Funktion `map`
|
||||
-- Aufgabe: Implementiere die rekursive Funktion `myMap`
|
||||
|
||||
-- Funktionssignatur
|
||||
map :: (a -> b) -> [a] -> [b]
|
||||
myMap :: (a -> b) -> [a] -> [b]
|
||||
|
||||
-- TODO: Implementiere die Funktion mit Rekursion
|
||||
map _ [] = undefined
|
||||
map f (x:xs) = undefined
|
||||
myMap _ [] = undefined
|
||||
myMap f (x:xs) = undefined
|
||||
|
||||
-- Testfälle
|
||||
test1 = map (*2) [1,2,3] == [2,4,6]
|
||||
test2 = map show [1,2,3] == ["1", "2", "3"]
|
||||
test3 = map (+1) [] == []
|
||||
test4 = map (const "a") [1,2,3] == ["a", "a", "a"]
|
||||
test1 = myMap (*2) [1,2,3] == [2,4,6]
|
||||
test2 = myMap show [1,2,3] == ["1", "2", "3"]
|
||||
test3 = myMap (+1) [] == []
|
||||
test4 = myMap (const "a") [1,2,3] == ["a", "a", "a"]
|
||||
|
||||
-- Hauptfunktion zum Testen
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "Teste map-Funktion..."
|
||||
putStrLn "Teste myMap-Funktion..."
|
||||
print test1
|
||||
print test2
|
||||
print test3
|
||||
|
|
|
@ -1,24 +1,32 @@
|
|||
-- Aufgabe: Implementiere die rekursive Funktion `zip`
|
||||
-- Aufgabe: Implementiere die rekursive Funktion `myZip`
|
||||
|
||||
-- Funktionssignatur
|
||||
zip :: [a] -> [b] -> [(a, b)]
|
||||
myZip :: [a] -> [b] -> [(a, b)]
|
||||
|
||||
-- TODO: Implementiere die Funktion mit Rekursion
|
||||
zip [] _ = undefined
|
||||
zip _ [] = undefined
|
||||
zip (x:xs) (y:ys) = undefined
|
||||
myZip [] _ = undefined
|
||||
myZip _ [] = undefined
|
||||
myZip (x:xs) (y:ys) = undefined
|
||||
|
||||
-- Testfälle
|
||||
test1 = zip [1,2,3] ['a', 'b', 'c'] == [(1, 'a'), (2, 'b'), (3, 'c')]
|
||||
test2 = zip [1,2] ["eins", "zwei", "drei"] == [(1, "eins"), (2, "zwei")]
|
||||
test3 = zip [True, False] [1,2,3] == [(True,1), (False,2)]
|
||||
test4 = zip [] [1,2,3] == []
|
||||
test5 = zip [1,2,3] [] == []
|
||||
-- Testfälle mit `null` und expliziten Typannotationen
|
||||
test1 :: Bool
|
||||
test1 = myZip [1,2,3] ['a', 'b', 'c'] == [(1, 'a'), (2, 'b'), (3, 'c')]
|
||||
|
||||
test2 :: Bool
|
||||
test2 = myZip [1,2] ["eins", "zwei", "drei"] == [(1, "eins"), (2, "zwei")]
|
||||
|
||||
test3 :: Bool
|
||||
test3 = myZip [True, False] [1,2,3] == [(True,1), (False,2)]
|
||||
|
||||
test4 :: Bool
|
||||
test4 = null (myZip [] [1,2,3])
|
||||
|
||||
test5 :: Bool
|
||||
test5 = null (myZip [1,2,3] [])
|
||||
-- Hauptfunktion zum Testen
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "Teste zip-Funktion..."
|
||||
putStrLn "Teste myZip-Funktion..."
|
||||
print test1
|
||||
print test2
|
||||
print test3
|
||||
|
|
Loading…
Reference in New Issue