Running program

mapFilter.hs:

[]
[1,2,3,4,5]
[4,3,2,99,54]
[4,7,22]
["John Smith","Wes Happen Ng","Holly Wood"]
[4,2025,25,49]
pass

Submitted files

mapFilter.hs:

-- 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 ()
main = do
  print $ stringsToNums []
  print $ stringsToNums ["1", "2", "3", "4", "5"]
  print $ mapAbsVal [-4, 3, 2, -99, 54]
  print $ mapAbsVal $ stringsToNums ["-4", "7", "-22"]
  print $ fullNames ["John", "Wes Happen", "Holly"] ["Smith", "Ng", "Wood"]
  print $ squarePositives [2, -3, 45, 5, 0, 7, -6]

Score

1/1

2026-02-09T20:26:53Z