haskell-workshop/solutions/block2/zip.hs

32 lines
708 B
Haskell

-- Rekursive Funktion myZip
myZip :: [a] -> [b] -> [(a, b)]
myZip [] _ = []
myZip _ [] = []
myZip (x:xs) (y:ys) = (x, y) : myZip xs ys
-- 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..."
print test1
print test2
print test3
print test4
print test5