I have the following function:
convertToStr :: [Int] -> String
convertToStr [] = []
convertToStr (int:ints)
| length (int:ints) == 1 = ((show (head (drop 0 (int:ints)))) ++ ", ")
| length (int:ints) == 2 = ((show (head (drop 0 (int:ints)))) ++ ", ") ++ ((show (head (drop 1 (int:ints)))) ++ ", ")
As can be seen above, I have managed to get the following output from this input:
> convertToStr [3,5]
"3, 5, "
I seem, however to be stuck with regard to being able to write a recursive definition. I’d like to convert a list of any length in [Int] elements to a string with that list and not have it limited as such.
Without explicit recursion you can do it using
mapand intersperse like thisEdit: And with manual recursion it’s like