[Haskell-cafe] Newbied question on IO Monad
mailing_list at istitutocolli.org
Tue Sep 12 09:18:22 EDT 2006
Il Tue, Sep 12, 2006 at 09:00:19AM -0400, Sara Kenedy ebbe a scrivere:
> Maybe what I talk is not clear.
> I want to take the input string sss of "update" to use in: writeFile
> "myFile.txt" sss of function "main" and get the value zzz from "main"
> to assign for the value return of "update". I think I need to change
> the way to declare two functions to get what I want, but I do not know
> update :: String -> String
> update sss = zzz
> main = do writeFile "myFile.txt" sss
> x <- callSystem "myFile.txt"
> y <- openFile "result.txt" ReadMode
> zzz <- hGetContents y
> return zzz
this is what you are trying to do with this code:
1. open a file and write to it an undefined string called "sss"
2. binding x with the value of a function name callSystem that takes a
string (we do not know what it returns because it's undefined in this
piece of code, but it must be a string).
3. open a file, "result.txt", read its content and put it in the IO
Instead you would like to insert into the file myFile.txt a string,
sss, that is the result of applying a function to the content of
"result.txt". Am I right?
If yes, here some code:
update :: String -> String
update sss = "This is the content of result.txt:\n" ++ sss
main = do y <- openFile "result.txt" ReadMode
zzz <- hGetContents y
writeFile "myFile.txt" $ update zzz
More information about the Haskell-Cafe