[decruft comments thomashartman1@gmail.com**20081003132829] hunk ./templates/macidupdatesandqueries.st 130 -
Macid is a bit complicated, and those type signatures can get cryptic. - hunk ./templates/macidupdatesandqueries.st 140 -
What makes some of these generated data declarations..... - -
*Main> :i query
-
query :: (Control.Monad.Trans.MonadIO m, QueryEvent ev res) => ev -> m res
-
-- Defined in HAppS.State.Transaction
-
-
This may seem slightly less cryptic if you specify the concrete type in this specific instance as follows. - -
:t query :: AskDatastore -> WebT IO (Data.Set.Set User)
-
query :: AskDatastore -> WebT IO (Data.Set.Set User) :: AskDatastore -> WebT IO (Data.Set.Set User)
-
-
Still pretty cryptic though -- and how did I figure out that concrete type in the first place? - -
For now, just take the concrete type as an article of faith, or read - tk happs type floundering in ghci if you really must know. - Let's do a couple of ghci info queries. - - - - -
-
-
-
-
*Main> :i AskDatastore
-
data AskDatastore = AskDatastore
-
-- Defined at src/AppStateSetBased.hs:(177,2)-(190,27)
-
instance Serialize AskDatastore
-
-- Defined at src/AppStateSetBased.hs:(177,2)-(190,27)
-
instance Version AskDatastore
-
-- Defined at src/AppStateSetBased.hs:(177,2)-(190,27)
-
*Main> :i askDatastore
-
askDatastore :: Query AppState (Data.Set.Set User)
-
-- Defined at src/AppStateSetBased.hs:42:0-11
-
-
Now loook at AppStateSetBased in yet another window. - Notice that there is no actual definition of AskDatastore. - This data type is derived by template haskell, and it is based on the askDatastore function, which - is a normal function. - -
askDatastore :: Query AppState (S.Set User)
-
askDatastore = do
-
(s :: AppState ) <- ask
-
return . appdatastore \$ s
-
-
-
-
The next thing to notice is that there are two kinds of template haskell definitions going on: queries, and updates. - We have already seen an example of a query: askDatastore/AskDatastore. If you look at the code in - spAddDummyData, and understand that this is a query, - - -
Now let's look at an update which is used in spAddDummyData: initializeDummyData/InitializeDummydata. - -
*Main> :i InitializeDummyData
-
data InitializeDummyData = InitializeDummyData
-
-- Defined at src/AppStateSetBased.hs:(177,2)-(190,27)
-
instance Serialize InitializeDummyData
-
-- Defined at src/AppStateSetBased.hs:(177,2)-(190,27)
-
instance Version InitializeDummyData
-
-- Defined at src/AppStateSetBased.hs:(177,2)-(190,27)
-
instance (Serialize InitializeDummyData, Serialize ()) =>
-
UpdateEvent InitializeDummyData ()
-
-- Defined at src/AppStateSetBased.hs:(177,2)-(190,27)
-
*Main> :i initializeDummyData
-
initializeDummyData :: Update AppState ()
-
-- Defined at src/AppStateSetBased.hs:169:0-18
-
-
-
If you compare the information about - -!$