Hi Mihai,<br>maybe the term "thread" in my mail is not correct.<br>What I mean is that a value gets stored by f and discovered by g.<br><br> <i>f,g :: IO ()<br>f = withFile "toto" WriteMode (flip hPutStr "42")<br>
g = withFile "toto" ReadMode hGetLine >>= (\s -> putStrLn $ "Answer:" ++ s)<br>
main = f >> g</i><br><br>Is it possible to do the same without files (the types must remain IO())?<br><br><br><div class="gmail_quote">On Wed, Aug 29, 2012 at 11:04 AM, Mihai Maruseac <span dir="ltr"><<a href="mailto:mihai.maruseac@gmail.com" target="_blank">mihai.maruseac@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>On Wed, Aug 29, 2012 at 10:58 AM, Corentin Dupont<br>
<<a href="mailto:corentin.dupont@gmail.com" target="_blank">corentin.dupont@gmail.com</a>> wrote:<br>
> Hi all,<br>
> there is something very basic that it seems escaped me.<br>
> For example with the following program f and g have type IO () and I can<br>
> thread a value between the two using a file.<br>
> Can I do the exact same (not changing the types of f and g) without a file?<br>
><br>
> f,g :: IO ()<br>
> f = withFile "toto" WriteMode (flip hPutStr "toto")<br>
> g = withFile "toto" ReadMode hGetLine >>= putStrLn<br>
> main = f >> g<br>
<br>
</div></div>Of course:<br>
<br>
f,g :: IO ()<br>
f = putStr "Answer: "<br>
g = print 42<br>
<br>
Main> f >> g<br>
Answer: 42<br>
<br>
The () is threaded by >>, not the file content<br>
<span><font color="#888888"><br>
--<br>
MM<br>
</font></span></blockquote></div><br>