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
|
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleInstances #-}
module Control.Monad.SariulClocks ( SariulClocks
, putSession
, getSession
, putScores
, getScores) where
import Control.Monad (liftM)
import Control.Monad.Trans (MonadIO, lift)
import Control.Monad.State (StateT, MonadState, get, put)
import Types.Session
import Types.Scores
import Types.Classes
import Network.CGI.Monad (CGIT, MonadCGI, cgiAddHeader, cgiGet)
newtype SariulClocks a =
SC { runSariulClocks :: StateT (Session, ScoresList) (CGIT IO) a }
deriving (Monad, MonadIO, MonadState (Session, ScoresList))
instance MonadCGI SariulClocks where
cgiAddHeader n v = SC . lift $ cgiAddHeader n v
cgiGet x = SC . lift $ cgiGet x
putSession :: Session -> SariulClocks ()
putSession s = do
(_, y) <- get
put (s, y)
getSession :: SariulClocks Session
getSession = liftM fst get
getScores :: SariulClocks ScoresList
getScores = liftM snd get
putScores :: ScoresList -> SariulClocks ()
putScores s = do
(x, _) <- get
put (x, s)
|