Hi all,<br><br>I wrote a simple interpreter that can be run in the console:<br><br><span style="font-family:courier new,monospace">data Interaction a b = Exit b<br>                     | Output b (Interaction a b)<br>                     | Input (a -&gt; Interaction a b)</span><br style="font-family:courier new,monospace">

<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">runConsole :: Interaction String String -&gt; IO ()</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">runConsole (Exit b) =<br>
    putStrLn $ &quot;Finished. Result: &quot; ++ b</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">runConsole (Output s cont) =<br>    putStrLn s &gt;&gt; runConsole cont</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">runConsole (Input f) =<br>
    putStr &quot;&gt; &quot; &gt;&gt; getLine &gt;&gt;= runConsole . f</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">interpreter :: Int -&gt; Interaction String String</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">interpreter i = interaction</span><br style="font-family:courier new,monospace">

<span style="font-family:courier new,monospace">  where </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    interaction  = Input input</span><br style="font-family:courier new,monospace">

<span style="font-family:courier new,monospace">    input &quot;exit&quot; = Exit (show i)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    input &quot;inc&quot;  = Output &quot;ok&quot; $ interpreter (i+1)</span><br style="font-family:courier new,monospace">

<span style="font-family:courier new,monospace">    input &quot;show&quot; = Output (show i) interaction</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">    input &quot;hello&quot;= Output &quot;Hello World!&quot; interaction</span><br style="font-family:courier new,monospace">

<span style="font-family:courier new,monospace">    input s      = Output (&quot;Whas&#39;s &#39;&quot; ++ s ++ &quot;&#39; ?&quot;) interaction</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">

<span style="font-family:courier new,monospace">main = runConsole .<br>  Output &quot;Known commands: show, inc, hello, exit&quot; $ interpreter 5</span><br><br>I have not yet gained a good understanding of the continuation monad, but I wonder if it could be used here. What would a clean solution look like? Perhaps there are other things that need to be changed as well?<br>
<br>Regards,<br>Tim<br><br>