I have a list that i partitioned with a function and I want to turn the lists inside of a list into strings.
list : [[0,0],[0,1]]
If i use show list, I will get "[[0,0],[0,1]]", which turns the whole list into a string. What output I want to get is ["[0,0]","[0,1]"], which turns only the objects inside the list into strings. I'm assuming I could use show in the function I use to partition the list but I'm not sure how to accomplish this.
The function that I am using
partition :: Int -> [a] -> [[a]]
partition n = go
where go [] = []
go xs = ys : go yss
where (ys, yss) = splitAt n xs
I assumed I could just change [[a]] to [string], but that didn't work. I don't really have a clue on how I could even insert show in this function either.
Is there a way to use show but only on the objects inside a list? If not I'd like to get a tip on how to edit this function to work
CodePudding user response:
Is there a way to use show but only on the objects inside a list?
Yes, you can just map
the show
function, to get a list of strings of the form that you say you want.
That is:
map show list
should give you what you're looking for.