I was wrong about what the problem was. The event handlers worked fine, and everything works now. I found the answer on http://gloss.ouroborus.net/, and the relevant paragraph is cited below. I apologize for asking a misleading question. I would delete the question but I don't see a way to do that.
from gloss.ouroborus.net:
Q: On my MacBook Pro under OSX, gloss programs freeze after displaying the first few frames. A: This can happen on dual GPU systems when the OS switches from the integrated GPU (baked into the processor) to the discrete one (separate from the main processor). The gloss program can sometimes draw a few frames before getting stuck, otherwise it just shows a black window. This is probably a bug in OSX not switching the graphics context properly. The work-around is to disable automatic GPU switching under System Preferences / Energy Saver.
Original question:
I wrote a game in Haskell Gloss which uses mouse click and keyboard handlers. It compiles and runs fine on a PC, but, while it compiles and loads on an Apple and presents the game screen, the mouse and keyboard handlers malfunction. The mouse handler recognizes that the mouse button has been been clicked, but reports the same pair of numbers for the mouse position no matter where the mouse is. The keyboard handler does not work for 's' and 'f', but the escape key DOES work.
Here are the handlers:
mousehandle::Event->(Board,Board)->IO(Board,Board)
mousehandle (EventKey (MouseButton LeftButton) Down _ pt@(x,y))
(board,solved) =
return (board',solved)
where
board' = if candidates == [] then board
else rotateCell board (fst (head candidates))
candidates = getCandidates (x,y) board
mousehandle (EventKey (Char 's') Down _ _ ) (board1, board2) = return (board2, board1)
mousehandle (EventKey (Char 'f') Down _ _ ) (board1, board2) = do
print "filename?"
ans <- getLine
games2File [board1, board2] ans
return (board1, board2)
mousehandle (EventKey (SpecialKey KeyEsc) Down _ _) _ = exitSuccess
mousehandle _ x = return x
I know what the returned mouse position coordinates are for each click because a trace in the function getCandidates prints them out to the console.
The computer is a Mac Book Pro. The Haskell used is GHC 7.6.3, installed as part of the full Haskell Platform. Gloss was installed with "cabal install gloss".
Any suggestions would be welcome.