[Haskell-beginners] IO vars
corentin.dupont at gmail.com
Wed Aug 29 11:21:06 CEST 2012
maybe the term "thread" in my mail is not correct.
What I mean is that a value gets stored by f and discovered by g.
*f,g :: IO ()
f = withFile "toto" WriteMode (flip hPutStr "42")
g = withFile "toto" ReadMode hGetLine >>= (\s -> putStrLn $ "Answer:" ++ s)
main = f >> g*
Is it possible to do the same without files (the types must remain IO())?
On Wed, Aug 29, 2012 at 11:04 AM, Mihai Maruseac
<mihai.maruseac at gmail.com>wrote:
> On Wed, Aug 29, 2012 at 10:58 AM, Corentin Dupont
> <corentin.dupont at gmail.com> wrote:
> > Hi all,
> > there is something very basic that it seems escaped me.
> > For example with the following program f and g have type IO () and I can
> > thread a value between the two using a file.
> > Can I do the exact same (not changing the types of f and g) without a
> > f,g :: IO ()
> > f = withFile "toto" WriteMode (flip hPutStr "toto")
> > g = withFile "toto" ReadMode hGetLine >>= putStrLn
> > main = f >> g
> Of course:
> f,g :: IO ()
> f = putStr "Answer: "
> g = print 42
> Main> f >> g
> Answer: 42
> The () is threaded by >>, not the file content
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners