There is a function defined in the Data.Char module called digitToInt . It takes a character and returns a number if the character can be interpreted as a hexadecimal digit.
If you want to use this function in the first example, where numbers are separated by a space, you need to avoid spaces. You can do this with a simple filter.
> map digitToInt $ filter (/=' ') "1 2 1 2 1 2 1" [1,2,1,2,1,2,1]
The second example where numbers that are not separated at all is even simpler because you don't need a filter
> map digitToInt "1212121" [1,2,1,2,1,2,1]
I would suggest that digitToInt is better than reading, because it does not depend on the type of expression, which can be complex (which in turn is how I found this post = P). Anyway, I'm new to haskell, so I could be wrong =).
user1459377
source share