How to convert list of numbers to list of strings(one string = one number from list) in Haskell.
[Int] -> [String]
Examples: [1,2,3,4] -> ["1","2","3","4"]
If you need to write a function to print an element from 0, this could be another solution
cp_log :: (Show a) => [a] -> String
cp_log [] = ""
cp_log [x] = (show x)
cp_log (x:xs) = (show x) ++ ", " ++ cp_log xs
A complete example can be the following one
cp_log :: (Show a) => [a] -> String
cp_log [] = ""
cp_log [x] = (show x)
cp_log (x:xs) = (show x) ++ ", " ++ cp_log xs
quick_sort :: (Ord a) => [a] -> [a]
quick_sort [] = []
quick_sort (x:xs) =
let smaller = quick_sort [a | a <- xs, a <= x]
bigger = quick_sort [a | a <- xs, a > x]
in smaller ++ [x] ++ bigger
main =
let sorted = (quick_sort [4, 5, 3, 2, 4, 3, 2])
in putStrLn (cp_log sorted)
map show. What you came up with is a rough equivalent of intercalate "," . map show. So your answer doesn't answers the question, and is excessively complicated at the same time. Please pay attention to what was the question about next time :)let with where, so I'll be able to remove my vote.
Int -> Stringyou could make a function[Int] -> [String]using map` map :: (a -> b) -> [a] -> [b]`