From: David R. <dr...@jd...> - 2003-10-13 13:52:14
|
The following code gives me "interesting" results: module Main where import Graphics.UI.WX main = start $ do f <- frame [text := "layout demo"] h <- staticText f [] hello h q <- button f [text := "quit", on command := close f] set f [layout := column 5 [widget h, widget q]] hello st = set st [text := "Hello world!", on click := \_ -> goodbye st] goodbye st = set st [text := "Goodbye world!", on click := \_ -> hello st] The code is intended to alternate between displaying "Hello world!" and "Goodbye world!" each time you click on the text. Instead, sometimes it crashes, and it never ends up getting back to displaying "Hello world!" after you've clicked it. It seems to occasionally go into a frenzy of alternating between "Hello world!" and "Goodbye world!" for quite a while--presumably stopping when some sort of a race condition has been satisfied. So my question is, am I supposed to be allowed to modify a callback function within that callback function? Obviously I could get the same functionality either using an IORef or by checking the current contents of the text, but I don't see why you shouldn't be able to modify a callback within the callback. Or perhaps there is some other more subtle problem going on here... -- David Roundy http://www.abridgegame.org |