[Haskell-cafe] Newbied question on IO Monad

Stefan Holdermans stefan at cs.uu.nl
Tue Sep 12 09:11:03 EDT 2006


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

I do not quite get what you want to accomplish. Is it something like  

   update   :: String -> IO String
   update s =  do
     writeFile "myFile.txt" sss
     callSystem "myFile.txt"
     z <- readFile "result.txt"
     return z

Note that update produces a value of type IO String now: in Haskell  
98, there is no escape from the IO monad.

Chances are that the above is not what you want. Can you then please  
explain one more time what it is what you're after?



More information about the Haskell-Cafe mailing list