title: Control thread to exit haskell application
body: <p>I'm brand new to Haskell and in messing around with a few samples I've got a problem where I can't stop the program. I'm using Windows 7 and using runhaskell from ght. Ctrl-c doesn't work so I have to resort to the task manager which is a bit of a pain.</p>
  
  <p>Instead of doing that how can I create a separate control thread that would wait until I typed q and then quit my Haskell application.</p>
  
  <p>The application I've got the problem with is of the format:</p>
  
  <pre><code>main = do
   h &lt;- connectTo server (PortNumber (fromInteger port))
   hSetBuffering h NoBuffering
   ... do some stuff with the socket handle ...
   listen h
  
  listen :: Handle -&gt; IO ()
  listen h = forever $ do
    t &lt;- hGetLine h
    let s = init t
    putStrLn s
  where
    forever a = do a; forever a
  </code></pre>
  
  <p>In pseudo-code what I'd like to have is:</p>
  
  <pre><code>main = do
    waitForQuit
    ... original program ...
  
  waitForQuit :: IO()
     option &lt;- getChar
     if option == 'q' then
       ... kill the app ... 
     else 
       waitForQuit
  </code></pre>