To give you more context, I have a soft using ACID state to store and retrieve values.<br>For example I have a function like that:<br><br>newPlayer :: PlayerName -> IO ()<br>newPlayer name = update $ AddPlayer name<br><br>
It seems that ACID uses a global state or a file to store the events... I'd like to suppress the ACID state for the moment, how should I do?<br>Change all the<i> IO () </i>types to <i>StateT Game IO ()</i>?<br>Indead the ACID state is started with:<br>
c <- localStartSystemState (Proxy :: Proxy Game)<br><br>Best,<br>C<br><br><div class="gmail_quote">On Wed, Aug 29, 2012 at 12:00 PM, Corentin Dupont <span dir="ltr"><<a href="mailto:corentin.dupont@gmail.com" target="_blank">corentin.dupont@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks Eugene and Ozgur.<br>I also looked on the side of IORef, but it doesn't looked to be a good solution since we have to use unsafePerformIO.<br>
<br>I have a big program to modify, and I want to pass some new data to existing functions of type IO(). I'd like to avoid changing all the function's types down the chain... What is the best way to do that?<div class="HOEnZb">
<div class="h5"><br>
<br><br><br><div class="gmail_quote">On Wed, Aug 29, 2012 at 11:43 AM, Ozgur Akgun <span dir="ltr"><<a href="mailto:ozgurakgun@gmail.com" target="_blank">ozgurakgun@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 class="gmail_quote">On 29 August 2012 10:21, Corentin Dupont <span dir="ltr"><<a href="mailto:corentin.dupont@gmail.com" target="_blank">corentin.dupont@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><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())?</div></blockquote></div><br></div>One can use an IORef to get a similar effect.<div><br></div><div><div><font face="courier new, monospace">import Data.IORef</font></div>
<div><font face="courier new, monospace">import System.IO.Unsafe</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">{-# NOINLINE toto #-}</font></div><div><font face="courier new, monospace">toto :: IORef String</font></div>
<div><font face="courier new, monospace">toto = unsafePerformIO (newIORef "")</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">f,g :: IO ()</font></div>
<div><font face="courier new, monospace">f = writeIORef toto "42"</font></div><div><font face="courier new, monospace">g = readIORef toto >>= (\s -> putStrLn $ "Answer:" ++ s)</font></div><div>
<font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">main = f >> g</font></div><div><br></div><div>HTH,</div><div>Ozgur</div>
</div>
</blockquote></div><br>
</div></div></blockquote></div><br>