Unexpected Acid Status Request Type (Happstack)

I am trying to expand the hashstack crash blog with some additional features: displaying a list of all tags on the main page.

My blog post is as follows:

data Blog = Blog { nextPostId :: PostId , posts :: IxSet Post , allTags :: [Text] } deriving (Data, Typeable) 

I get a blog post by id as follows (copypasted from crash course):

 -- Models.hs postById :: PostId -> Query Blog (Maybe Post) postById pid = do Blog{..} <- ask return $ getOne $ posts @= pid -- Controller.hs viewPage :: AcidState Blog -> ServerPart Response viewPage acid = do pid <- PostId <$> lookRead "id" mPost <- query' acid (PostById pid) ... -- mPost has type Maybe Post here ... 

And everything works well.

When I try to query all tags in the same way:

 -- Models.hs getTags :: Query Blog [Text] getTags = do Blog{..} <- ask return allTags -- Controller.hs serveTags :: AcidState Blog -> [Text] serveTags acid = query' acid GetTags 

This will not work. Error Stack Trace:

 Blog/Controllers.hs:154:18: Couldn't match type `[Text]' with `Text' Expected type: [Text] Actual type: [acid-state-0.8.1:Data.Acid.Common.EventResult GetTags] In the return type of a call of query' In the expression: query' acid GetTags 

I can't understand why the query' return type is [EventResult GetTags] , whereas it should be [Text] .

What is the reason for this error? Is there any way to fix this?

+4
source share
1 answer

The problem is your type signature in the serveTags function, it should be monodic:

 serveTags :: MonadIO m => AcidState Blog -> m [Text] serveTags acid = query' acid GetTags 

EventResult is a type family that is resolved here before [Text] . Since query' is monadic, your type signature was resolved to a list monad, i.e. m Text , where m is the list monad, thus a confusing error message.

+2
source

All Articles