Haskell SOEGraphics window does not close

I am currently following the exercises in the book: “Haskell Expression School” and reached chapter three on creating graphics. The book uses the SOEGraphics module and demonstrates how to draw plain text in a window and then close it with the click of a button.

However, when, after compilation and execution, I found that although the window appears with the text on the screen, the window refuses to close no matter which keys I press, or the focus is on the command line or the window itself.

Here is the source code from the book:

module Main where
import SOE
main =  runGraphics(
        do  w <- openWindow
                "My First Graphics Program" (300, 300)
            drawInWindow w (text(100,200) "HelloGraphicsWorld")
            k <- getKey w
            closeWindow w
        )

The only way to close a window is to force it to exit using CTRL-C. Is there something I forgot with my code? The program was compiled using GHC 7.4.1 and launched on Ubuntu.

+5
3

getKeyChar getKey. -, / .

+2

SOE, 9 . , GHCi 7.4.1 Ubuntu (12.04). , DuckMaestro :

getKeyChar SOE. getKeyEx:

getKeyEx :: Window -> Bool -> IO Char

SOE, , , > Graphics.HGL.Utils.

, getKey SOE, getKeyEx .

  • getKeyEx SOE
  • , , k <- getKey w k <- getKeyEx w True
0

Daniel is right, but it seemed strange to me that getKeyEx works when getKey, which just uses getKeyEx, doesn't work. So I looked. The problem is pretty clear. Here is the existing code for getKey

getKey win = do
  ch <- getKeyEx win True
  if ch == '\x0' then return ch
    else getKeyEx win False

Here is what it should be

getKey win = do
  ch <- getKeyEx win True
  if ch /= '\x0' then return ch
    else getKeyEx win False

Make this fix and getKey works.

0
source

All Articles