title: Difference for ncurses between interpreted and compiled Haskell?
body: <p>I have a strange problem with functions <code>timeout</code> and <code>getch</code> from the ncurses library used in Haskell. When I use them from GHCi or runhaskell, they work as expected -- <code>getch</code> waits for the number of miliseconds given to <code>timeout</code> and then returns, even if no input was given. But when I <em>compile</em> the same file using GHC, <code>getch</code> returns immediately.</p>
  
  <p>I tried two ncurses bindings for Haskell; <code>hscurses</code>:</p>
  
  <pre><code>import UI.HSCurses.Curses
  
  main = do
    initCurses
    timeout 1000
    c &lt;- getch
    endWin
    print c
  </code></pre>
  
  <p>and <code>ncurses</code>:</p>
  
  <pre><code>import UI.NCurses
  
  main = do
    e &lt;- runCurses $ do
      win &lt;- defaultWindow
      getEvent win $ Just 1000
    print e
  </code></pre>
  
  <p>Both behave the same strange way described before.</p>
  
  <p>I also tried equivalent program in C:</p>
  
  <pre><code>#include &lt;ncurses.h&gt;
  
  int main()
  {
    initscr();
    wtimeout(stdscr,1000);
    int c = getch();
    endwin();
    printf("%d\n", c);
    return 0;
  }
  </code></pre>
  
  <p>This one works as expected.</p>
  
  <p>So my question is: what can make the difference when using terminal from interpreted and from compiled Haskell? Do runhaskell and ghci modify some subtle terminal settings? Or does the compiled code load libraries a different way?</p>
  
  <p><strong>ADDED:</strong></p>
  
  <p>I tried to call a the C program from compiled Haskell using FFI and it returned immediately (which is incorrect). I think that means that the problem isn't in the libraries, but somewhere in GHC's runtime.</p>