[Haskell-cafe] Re: Newbied question on IO Monad

Stephane Bortzmeyer bortzmeyer at nic.fr
Tue Sep 12 09:11:36 EDT 2006


On Tue, Sep 12, 2006 at 09:00:19AM -0400,
 Sara Kenedy <sarakenedy at gmail.com> wrote 
 a message of 68 lines which said:

> Maybe what I talk is not clear.

Do not worry, not all the haskell-cafe readers speak english. (I'm
french, for instance.)

> 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".

>From a newbie to another newbie: I do not think it is possible. "There
is no way out of the IO monad, once you're in it."

See the explanations in the page indicated by Henning Thielemann :

http://haskell.org/hawiki/ThatAnnoyingIoType

This should work (not tested):

update :: String -> IO String
update sss = do 
               writeFile "myFile.txt" sss
               x <- callSystem "myFile.txt"
               y <- openFile "result.txt" ReadMode
               zzz <- hGetContents y
               return zzz

main = update "Foobar"


More information about the Haskell-Cafe mailing list