I have a strange problem with functions timeout
and getch
from the ncurses library used in Haskell. When I use them from GHCi or runhaskell, they work as expected -- getch
waits for the number of miliseconds given to timeout
and then returns, even if no input was given. But when I compile the same file using GHC, getch
returns immediately.
I tried two ncurses bindings for Haskell; hscurses
:
import UI.HSCurses.Curses
main = do
initCurses
timeout 1000
c <- getch
endWin
print c
and ncurses
:
import UI.NCurses
main = do
e <- runCurses $ do
win <- defaultWindow
getEvent win $ Just 1000
print e
Both behave the same strange way described before.
I also tried equivalent program in C:
#include <ncurses.h>
int main()
{
initscr();
wtimeout(stdscr,1000);
int c = getch();
endwin();
printf("%d\n", c);
return 0;
}
This one works as expected.
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?
ADDED:
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.