Hello Haskell'rs,<br>
<br>
I've been playing with threads and I tried to do a toy example (that used java) from a class.<br>
When run, the program should print a prompt and accept commands just like a linux shell.&nbsp; It doesn't have to do anything<br>
fancy, just spawn new threads that make system calls when commands are entered at the prompt.<br>
The problem is that the UI doesn't work very well.&nbsp; It will seem fine
at first, but in order to get back a prompt you have to hit enter one
more time than you should.&nbsp; I've tried playing with the buffering
settings but it seems to cause the same problem no matter what.&nbsp; The
problem seems to be coming from calls of the form<br>
(forkIO . system_) &quot;ls /usr/bin&quot;<br>
Just entering this into ghci I get the same thing where I need to hit enter *again* in order to get back to the ghci prompt.<br>
I'm sure this is something silly on my part, but it is rather confusing.<br>
<br>
import Control.Concurrent<br>
import System<br>
import System.IO<br>
<br>
main = do<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putStr &quot;&gt;&quot;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; z &lt;- getLine<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; runCommands z<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; main<br>
<br>
genWords :: Char -&gt; String -&gt; [String]<br>
genWords c s = gwhelper c s [] []<br>
<br>
gwhelper :: Char -&gt; String -&gt; [String] -&gt; String -&gt; [String]<br>
gwhelper c [] acc temp = acc ++ [(reverse temp)]<br>
gwhelper c (x:xs) acc temp | x /= c =&nbsp; gwhelper c xs acc (x:temp)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | otherwise = gwhelper c xs (acc++[(reverse temp)]) []<br>
<br>
<br>
runCommands s = mapM_ (forkIO .system_) (genWords '&amp;' s)<br>
<br>
system_ :: String -&gt; IO ()<br>
system_ s = do<br>
&nbsp; system s<br>
&nbsp; return ()<br>