Hello,<br><br>I made a GCL compiler using Alex and Happy and now I&#39;m making the interpreter to that program. Here&#39;s the deal:<br><br>First of all, I&#39;m no expert in the usage of monads. Now:<br><br>Whenever a &quot;show&quot; instruction is found in any GCL program while the interpretation is being done it is supposed to print on the stdout the string or the aritmetic expresion it was called with, so I guessed I need to run an IO operation and continue the interpretation of my program. I managed to do this using unsafePerformIO and `seq` like is shown below. My question is: Is it safe to use it this way? So far it is working great, but I need to be sure I&#39;m using it in a &quot;safe&quot; way. Like I said, I&#39;m no expert in monads and the System.IO.Unsafe documentation says:<br>

<br>&quot;<br><table class="vanilla" cellpadding="0" cellspacing="0"><tbody><tr><td class="s15"></td></tr><tr><td class="topdecl"><table class="declbar"><tbody><tr><td class="declname"><a name="v:unsafePerformIO"></a><a name="v:unsafePerformIO"></a><b>unsafePerformIO</b> ::  <a href="http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO">IO</a> a -&gt; a</td>

</tr></tbody></table></td></tr></tbody></table><br>This is the &quot;back door&quot; into the <tt><a href="http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO">IO</a></tt> monad, allowing
<tt><a href="http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO">IO</a></tt> computation to be performed at any time.  For
this to be safe, the <tt><a href="http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO">IO</a></tt> computation should be
free of side effects and independent of its environment.
<br>&quot;<br><br>I don&#39;t know if the IO computation I&#39;m doing is free of side effects and independent of its enviroment :s. (is just hPutStr stdout ....)<br><br>Also I&#39;ve read something about my code not being executed for sure or something like that. Can somebody check the code and tell me if I&#39;m &quot;safe&quot; with it?<br>

<br>Thanks a lot!<br><br>Here&#39;s the code:<br><br>-- Tabla is my Symbol Table of the program being interpreted<br>evalInstruccion:: Instruccion -&gt; Tabla -&gt; Tabla<br>evalInstruccion (ShowY showY) tabla = myRunIO (evalShow showY tabla)<br>

evalInstruccion _ tabla = tabla      -- There are many other Instructions here missing wich are not relevant to my question<br><br>{-# NOINLINE myRunIO #-}<br>myRunIO:: (Tabla, IO()) -&gt; Tabla<br>myRunIO tupla = ((unsafePerformIO (snd tupla)) `seq` (fst tupla)) -- Here&#39;s the unsafePerformIO.... Am I safe?<br>

<br>evalShow:: ShowY -&gt; Tabla -&gt; (Tabla, IO())<br>evalShow (ShowS string) tabla = (tabla,(hPutStr stdout string))<br>evalShow (ShowE expr) tabla = (tabla,(hPutStr stdout (show (evalExpr expr tabla)))) -- Don&#39;t worry about evalExpr, it works and returns an Int<br>