Apply two functions to a list of tuples
I have a list of tuples containing information in the following form as so:
carDatabase :: [Car] carDatabase = [("Ford", "Focus", 2003, [("Autotrader", 9995), ("Parkers", 9495), ("Motors", 9995)]), ("Vauxhall", "Corsa", 2005, [("Autotrader", 5995), ("FOW", 7000), ("Gumtree", 6500)]), ...]
And what I am trying to do is map this list to return a list of strings with the first element of each tuple (I have a function that does this with carMan (x,_,_,_) = x) but also using the toLower function and I cannot work out a way to combine them, be it with function compositions or mapping a map etc.
This is the closest I've got.
mapTest :: [Car] -> [String] mapTest cs = map toLower (map carMan cs)
Any help would be appreciated.
This is the error I get with:
mapTest :: [Car] -> [String] mapTest cs = map (toLower . carMan) cs Couldn't match type ‘Char’ with ‘[Char]’ Expected type: Char -> String Actual type: Char -> Char In the first argument of ‘(.)’, namely ‘toLower’ In the first argument of ‘map’, namely ‘(toLower . carMan)’ cars.hs:197:37: Couldn't match type ‘[Char]’ with ‘Char’ Expected type: [(Char, String, Int, [(String, Int)])] Actual type: [Car] In the second argument of ‘map’, namely ‘cs’ In the expression: map (toLower . carMan) cs
You can do this with function composition using .
map ((map toLower) . carMan) cs
Or make it a helper function:
strLower :: String -> String strLower = map toLower mapTest :: [Car] -> [String] mapTest = map (strLower . carMan)