@@ -16,7 +16,7 @@ import Happstack.Data.IxSet
1616import qualified Data.Map as M
1717
1818------------------------------------------------
19- -- Define a component of state
19+ -- Define a component of state
2020--
2121-- Real examples are HelpReqs, FlashMsgs, and sessions
2222-- really you should put components in their own modules.
@@ -29,15 +29,13 @@ import qualified Data.Map as M
2929-- Lets start with defining a simple state component: Session
3030type SesKey = Integer
3131type ETime = Integer
32- newtype OldSession val = OldSession { old_unsession :: [(SesKey ,(ETime ,val ))]}
33- deriving (Typeable )
32+ newtype OldSession val = OldSession { old_unsession :: [(SesKey ,(ETime ,val ))]}
3433
3534instance Version (OldSession val )
3635$ (deriveSerialize ''OldSession)
3736
3837
3938newtype Session val = Session { unsession :: M. Map SesKey (ETime ,val ) }
40- deriving (Typeable )
4139
4240instance Migrate (OldSession val ) (Session val ) where
4341 migrate (OldSession sess) = Session (M. fromList sess)
@@ -71,7 +69,7 @@ getSession :: SesKey -> Query (Session val) (Maybe val)
7169getSession key = do val <- liftM (M. lookup key) askSession
7270 return (liftM snd val)
7371
74- setSession key val = do
72+ setSession key val = do
7573 t <- getTime
7674 modSession $ M. insert key (t,val)
7775 return ()
@@ -97,30 +95,30 @@ numSessions = proxyQuery $ liftM M.size askSession
9795
9896-- Declare these as methods. So you can access them from any IO via (query $
9997-- GetSession key) or (update $ setSession key val). When we can have
100- -- Data for phantom types in 6.8.2 this will look nicer
98+ -- Data for phantom types in 6.8.2 this will look nicer
10199
102- $ (mkMethods ''Session
103- ['newSession,'setSession, 'cleanSessions,'numSessions ,'getSession])
100+ $ (mkMethods ''Session
101+ ['newSession,'setSession, 'cleanSessions,'numSessions ,'getSession])
104102
105103-- Sometimes you want maintenance on your component that the user
106104-- doesn't want to worry about.
107105
108106maintainSessions v = do update $ CleanSessions 3600000 v
109107 threadDelay (10 ^ 6 * 10 ) -- Once every 10 seconds
110- maintainSessions v
108+ maintainSessions v
111109
112110instance (Serialize a ) => Component (Session a ) where
113111 type Dependencies (Session a ) = End
114112 initialValue = Session M. empty
115113
116- -- All components need an atStart declaration though the list can be empty
114+ -- All components need an atStart declaration though the list can be empty
117115
118116-- Now we repeat the above for a more trivial example so we have
119- -- multiple components in state. But we'll use the more concise deriveAll syntax
117+ -- multiple components in state. But we'll use the more concise deriveAll syntax
120118-- so you don't deal with the boilerplate of a zillion deriving declarations on each type.
121119
122- data UserComponent key = UserComponent { unUserComponent :: key } deriving ( Typeable )
123- data SingletonComponent = SingletonComponent { unSingleton :: String } deriving ( Typeable )
120+ data UserComponent key = UserComponent { unUserComponent :: key }
121+ data SingletonComponent = SingletonComponent { unSingleton :: String }
124122
125123instance Version (UserComponent key )
126124$ (deriveSerialize ''UserComponent)
@@ -183,7 +181,7 @@ $(deriveAll [''Show,''Default, ''Read]
183181
184182data State = State { privateInt :: Int
185183 , privateString :: String
186- } deriving ( Typeable )
184+ }
187185
188186instance Version State
189187$ (deriveSerialize ''State)
@@ -227,7 +225,7 @@ impl = dir "setGet" $ msum
227225 mbComp <- getData
228226 comp <- maybe mzero return mbComp
229227 liftIO $ update $ SetComponent (comp :: Int )
230- ok comp -- returned as <?xml v=1.0?><component>blah</component>.
228+ ok comp -- returned as <?xml v=1.0?><component>blah</component>.
231229 -- add the xslt wrapper to style the xml
232230 -- or write your own ToMessage instance for your return types
233231 ]
0 commit comments