forked from Happstack/happstack-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultimasterTest2.hs
More file actions
42 lines (33 loc) · 1.15 KB
/
MultimasterTest2.hs
File metadata and controls
42 lines (33 loc) · 1.15 KB
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
41
42
{-# LANGUAGE TemplateHaskell, MultiParamTypeClasses, TypeFamilies, FlexibleContexts #-}
module Main where
import Happstack.Server
import Happstack.State
import Control.Monad.State
import Control.Monad.Reader
data MyState = MyState Int
instance Version MyState
$(deriveSerialize ''MyState)
succVal :: Update MyState ()
succVal = modify (\(MyState n) -> MyState (succ n))
predVal :: Update MyState ()
predVal = modify (\(MyState n) -> MyState (pred n))
getVal :: Query MyState Int
getVal = do MyState n <- ask
return n
$(mkMethods ''MyState [ 'succVal
, 'predVal
, 'getVal])
instance Component MyState where
type Dependencies MyState = End
initialValue = MyState 0
rootState :: Proxy MyState
rootState = Proxy
main :: IO ()
main = do ctl <- startSystemStateMultimaster rootState
simpleHTTP nullConf{port=8001} $ msum
[ dir "succ" $ do update SuccVal
seeOther "/" ""
, dir "pred" $ do update PredVal
seeOther "/" ""
, do val <- query GetVal
ok $ "Value is: " ++ show val ]