I normally program in Java and Haskell to me seems completely alien and weird.
All I want to do is read the contents of a file into a big string then be able to do stuff with that string like split it on newline and store it in a list then split each line in that list with a " " and store them somewhere but I have read and read online without any sort of enlightenment. Apparently I cannot convert an IO String to a String? But then how am I ever going to be able to use the functions I have written that need an input String?
What I have so far...
read :: String -> IO ()
read input = do
inh <- openFile input ReadMode
inputString <- hGetContents inh
putStr (storeReadFile inputString)
hClose inh
storeReadFile :: String -> String
storeReadFile input = input
split :: String -> Char -> [String]
split [] delim = [""]
split (c:cs) delim
| c == delim = "" : rest
| otherwise = (c : head rest) : tail rest
where
rest = split cs delim
I guess I eventually want to be able to say in some main method that you call the read function use the value it gets (ie the inputString into which the contents of the file were read) then split it on the newline and store that in a list ...then do something with that list etc.
How can I do this?
Thanks