{-# OPTIONS -fglasgow-exts -farrows -fno-monomorphism-restriction #-} import FG -- A Widget with three buttons "Inc", "Dec" and "Reset". "Dec" is -- disabled when the count is 0. Does not actually display the count. -- The output value is the current value of the counter. counter :: Widget WidgetP Int counter = proc p -> hbox [] (proc _ -> do rec inc <- tag (+1) <<< button [text "Inc"] -< def dec <- tag (+(-1)) <<< button [text "Dec"] -< [enabled (c > 0)] reset <- tag (const 0) <<< button [text "Reset"] -< def cs@(_,c) <- hold 0 -< onEvent (\f -> Just $ f c) Nothing (inc >< dec >< reset) returnA -< cs) -< (p, ()) -- The main FG. Connects the value of the counter to a Label. mainFG :: Container () () mainFG = vbox [spacing 2] $ proc _ -> do (_,c) <- counter -< def label [] -< [text $ show c] returnA -< () main :: IO () main = runFG mainFG