one solution
convert :: String -> [[String]]
convert = map (map return) . lines
should do the trick
remark
the return
here is a neat trick to write \c -> [c]
- wrapping a Char
into a singleton list as lists are a monad
how it works
Let me try to explain this:
lines
will split the input into lines: [String]
which each element in this list being one line
- the outer
map (...) . lines
will then apply the function in (...)
to each of this lines
- the function inside:
map return
will again map each character of a line (remember: a String
is just a list of Char
) and will so apply return
to each of this characters
- now
return
here will just take a character and put it into a singleton list: 'a' -> [a] = "a"
which is exactly what you wanted
your example
Prelude> convert "000011S\n0001110\n001G111\n0001000\n"
[["0","0","0","0","1","1","S"]
,["0","0","0","1","1","1","0"]
,["0","0","1","G","1","1","1"]
,["0","0","0","1","0","0","0"]]
concerning your comment
if you expect convert :: String -> [[Char]]
(which is just String -> [String]
then all you need is convert = lines
!
String
is just[Char]
? – Random DevString
s because you did the doublemap
there - can you please edit your question and provide the input and the expected output? I really have trouble if your input is supposed to be"a10b\ndot2"
or if this is the expected outupt – Random Dev