From 9a8d2abfdbb785aed9f73b14f0504a240ec1f50b Mon Sep 17 00:00:00 2001 From: Yuri Tatishchev Date: Mon, 9 Feb 2026 12:43:26 -0800 Subject: [PATCH] lab04: impl --- lab04/mapFilter.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lab04/mapFilter.hs b/lab04/mapFilter.hs index f381325..90f9291 100644 --- a/lab04/mapFilter.hs +++ b/lab04/mapFilter.hs @@ -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] - \ No newline at end of file + print $ squarePositives [2, -3, 45, 5, 0, 7, -6]