how to read a file's content to a string?
Jay Cox
sqrtofone@yahoo.com
Tue, 5 Mar 2002 18:36:01 -0600 (CST)
On Tue, 5 Mar 2002, Zhe Fu wrote:
> I want to read a file's content into a string.
>
> content :: FilePath -> String
> content f = readFile f
>
> But when there is a type error:
>
> Type error in explicitly typed binding
> *** Term : content
> *** Type : FilePath -> IO String
> *** Does not match : FilePath -> String
>
> How can I solve it?
>
> Thanks.
>
> Zhe
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
Essentially, what you are trying to do is invalid. you have to write
some function that results in a IO String.
I haven't read these but they might help.
(cut and paste from haskell wiki front page)
ThatAnnoyingIoType: I have an IO String but I need a String - what do I do
now?
http://haskell.org/wiki/wiki?ThatAnnoyingIoType
UsingIo: What's that IO type anyway? How do I do I/O in Haskell?
http://haskell.org/wiki/wiki?UsingIo
Jay Cox