[Haskell-cafe] Newbied question on IO Monad
sarakenedy at gmail.com
Tue Sep 12 09:00:19 EDT 2006
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
On 9/12/06, Andrea Rossato <mailing_list at istitutocolli.org> wrote:
> Il Tue, Sep 12, 2006 at 08:05:42AM -0400, Sara Kenedy ebbe a scrivere:
> > Hello all,
> > update :: String -> String
> > update sss = ...
> > main = do writeFile "myFile.txt" sss
> > x <- callSystem "myFile.txt"
> > y <- openFile "result.txt" ReadMode
> > zzz <- hGetContents y
> > return zzz
> > I know that function main returns IO String, function update returns
> > String. And my purpose is to get the string zzz from main for the
> > value return of function update. But I do not know which way I can do.
> Did you mean something like this?
> update :: String -> String
> update sss = "Hi! " ++ sss
> main = do writeFile "myFile.txt" $ update "What are you trying to do?"
> x <- callSystem "myFile.txt"
> y <- openFile "result.txt" ReadMode
> zzz <- hGetContents y
> return zzz
> In this case main :: IO String so you will not see any output (quite
> I'd suggest you to have a look at this tutorial that explain quite
> well the IO Monad:
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe