File: CounterWithBoundedLog.hs

package info (click to toggle)
washngo 2.9-4.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,876 kB
  • ctags: 273
  • sloc: haskell: 54,162; makefile: 1,086; ansic: 305; sh: 153; sql: 13
file content (40 lines) | stat: -rw-r--r-- 942 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
--  2001, 2002 Peter Thiemann
module Main where

import Prelude hiding (map, span, head, div)
import WASH.CGI.CGI

import qualified Persistent2 as P

counterStore :: CGI (P.T Int)
counterStore = P.init "Counter" 0

main = 
  run mainCGI

mainCGI =
  forever counter

counter = do
  counterHandle <- counterStore
  counterValue <- P.get counterHandle
  standardQuery "Counter" $ p $
   do text "Current counter value "
      text (show counterValue)
      br empty
      submit0 (count counterHandle (counterValue+1)) (fieldVALUE "Increment")
      submit0 (count counterHandle (counterValue-1)) (fieldVALUE "Decrement")

count h n = do
  r <- P.set h n
  case r of
    Just _ -> 
      return ()
    Nothing ->
      standardQuery "CounterMistake" $ p $
	do text "Your attempt to set the counter to "
	   text (show n)
	   text " was not successful. "
	   text "Someone else was quicker :-)"
	   submit0 (return ()) (fieldVALUE "Continue")