I am trying to use splitOn function in haskell to split a string based on some delimiters. So the splitOn function returns data of type [[Char]], but the compiler is showing error saying that the expected type is IO a.
The line of code which is failing is:
splitOn "x" "1 2, 3"
Please suggest.
If you’ve written something like
xs <- splitOn "x" lineand simply want to bind a name tosplitOn "x" line, then you can uselet xs = splitOn "x" line.<-is for binding values from IO actions, rather than assigning names to pure values.Otherwise, you’ve presumably done something like this:
You’re using a
[String], but you need an IO action. You need to do something with the pure result you’ve got to turn it into an IO computation.You could print the list out, as GHCi would:
Or you could use
return, if you simply want to return the pure computation to be used in other IO actions:It all depends on how you want to process the data.