
I'm guessing in the .hs file, you have this in a do block? Something like:
foo = do
contents <- readFile
words contents
If so, the problem is the return type of `words`. Each line of the do block
has to have an IO value, and words is a pure function. To lift its result
into the monad, use the aptly-named `pure` function:
foo = do
contents <- readFile
pure $ words contents
On Tue, Mar 26, 2019, 8:35 PM Yugesh Kothari
Hi,
I am trying to read data from a file. When I do- ghci> contents <- readFile "file.txt" ghci> words contents
Then everything works.
The same thing when done in a .hs file gives an IO String vs [String] error.
Why is that so? _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners