25 lines
568 B
Haskell
25 lines
568 B
Haskell
-- Lösung: Rekursive Implementierung der map-Funktion
|
|
|
|
-- Funktionssignatur
|
|
-- Lösung: Rekursive Implementierung der map-Funktion
|
|
|
|
-- Funktionssignatur
|
|
myMap :: (a -> b) -> [a] -> [b]
|
|
myMap _ [] = []
|
|
myMap f (x:xs) = f x : map f xs
|
|
|
|
-- Testfälle
|
|
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..."
|
|
print test1
|
|
print test2
|
|
print test3
|
|
print test4
|