haskell-workshop/exercises/block2/1-map/map.hs

24 lines
548 B
Haskell

-- Aufgabe: Implementiere die rekursive Funktion `myMap`
-- Funktionssignatur
myMap :: (a -> b) -> [a] -> [b]
-- TODO: Implementiere die Funktion mit Rekursion
myMap _ [] = undefined
myMap f (x:xs) = undefined
-- 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 myMap-Funktion..."
print test1
print test2
print test3
print test4