lab04: impl

This commit is contained in:
2026-02-09 12:43:26 -08:00
parent b210cb5b32
commit 9a8d2abfdb

View File

@@ -1,17 +1,23 @@
-- USING MAP, convert a list of Strings to a list of Integers.
stringsToNums :: [String] -> [Integer]
stringsToNums l = map read l
-- USING MAP, take a list of integers and return a list with
-- the equivalent absolute values.
mapAbsVal :: [Integer] -> [Integer]
mapAbsVal l = map abs l
-- USING ZIPWITH, concatenate a list of first names with
-- a list of last names to produce a list of full names.
fullNames :: [String] -> [String] -> [String]
fullNames l = zipWith (\first last -> first ++ " " ++ last) l
-- USING MAP AND FILTER, square all positive numbers in a list;
-- strip out 0 and negative numbers.
squarePositives :: [Integer] -> [Integer]
squarePositives l = map (\x -> x * x) $ filter (\x -> x > 0) l
main :: IO ()
@@ -21,5 +27,4 @@ main = do
print $ mapAbsVal [-4, 3, 2, -99, 54]
print $ mapAbsVal $ stringsToNums ["-4", "7", "-22"]
print $ fullNames ["John", "Wes Happen", "Holly"] ["Smith", "Ng", "Wood"]
print $ squarePostives [2, -3, 45, 5, 0, 7, -6]
print $ squarePositives [2, -3, 45, 5, 0, 7, -6]