I normally program in Java and Haskell to me seems completely alien and weird.
That's because it is. I normally program in Haskell and Java seems deficient and limiting. I don't think you really get a benefit out of learning Haskell until you learn more about type classes. But the benefit is huge.All I want to do is read the contents of a file into a big string
Note that there is a function, readFile :: FilePath -> IO String , that does the opening and closing for you.then be able to do stuff with that string ... 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?
He he he he he he he.
If I want to read a file and pass it to a function that needs a String, it's as simple as this:
countSpaces :: String -> Int
countSpaces s = length (filter (== ' ') s)
countSpacesInFile :: String -> IO Int
countSpacesInFile fileName = do
text <- readFile fileName
return (countSpaces text)
-- our program counts the number of spaces in input.txt
main :: IO ()
main = do
n <- countSpacesInFile "input.txt"
print n
In fact, you were already doing that, no? You were reading the contents of the file and passing it to the function storeReadFile, which happened to be doing nothing to it.