[Haskell-beginners] rolling my own split
apolishc at gmail.com
Thu Mar 27 04:41:03 UTC 2014
I am relatively new to Haskell, having spent the last half a decade or so
developing in Ruby. I am attempting to (for the sake of exercise) implement
a split function from the ground up in Haskell, and for the life of me I
can not figure out why it doesn't work. Without further ado:
module MyAwesomeModule where
import qualified Data.Text as T
outputSplit :: String -> [String] -> IO ()
outputSplit s tokens = print $ splitRecursive tokens s
splitRecursive :: [String] -> String -> [String]
splitRecursive tokens s = splitOneOf tokens s
splitOneOf :: [String] -> String -> [String]
splitOneOf  s = 
splitOneOf (t:tokens) s = map (splitOneOf tokens)(map (T.unpack)
(T.splitOn (T.pack t) (T.pack s))) ++ (splitOneOf tokens s)
which errors out with:
Couldn't match type `[Char]' with `Char'
Expected type: String -> String
Actual type: String -> [String]
In the return type of a call of `splitOneOf'
In the first argument of `map', namely `(splitOneOf tokens)'
In the first argument of `(++)', namely
(map (T.unpack) (T.splitOn (T.pack t) (T.pack s)))'
Failed, modules loaded: none.
If anyone has any ideas, that would be awesome! And yes, I'm aware of
Data.List.Split, like I said, trying to roll my own....
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners