24 lines
530 B
Haskell
24 lines
530 B
Haskell
-- Aufgabe: Implementiere die rekursive Funktion `map`
|
|
|
|
-- Funktionssignatur
|
|
map :: (a -> b) -> [a] -> [b]
|
|
|
|
-- TODO: Implementiere die Funktion mit Rekursion
|
|
map _ [] = undefined
|
|
map 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"]
|
|
|
|
-- Hauptfunktion zum Testen
|
|
main :: IO ()
|
|
main = do
|
|
putStrLn "Teste map-Funktion..."
|
|
print test1
|
|
print test2
|
|
print test3
|
|
print test4
|