Going through happstack-lite tutorial:
we build functions that have return type of ServerPart Reponse
:
homePage :: ServerPart Response
however, in web-routes crash course, our functions change signature to the following:
homePage :: RouteT Sitemap (ServerPartT IO) Response
Didn't we have ServerPart before, and not ServerPartT? Also, is there an easier way to switch to web-routes, without changing every method's type signature?
ServerPart
is simply defined as type ServerPart a = ServerPartT IO a
. In Happstack 8 we might change this to type ServerPart = ServerPartT IO
which would mean we could write types like RouteT Sitemap ServerPart Response
, but until then, we have to use ServerPartT
directly because type synonyms can't be "partially applied". However, they are the same types. That is, ServerPart Response
is just an alias for ServerPartT IO Response
.
Also, is there an easier way to switch to web-routes, without changing every method's type signature?
Not really. I like to define my own type for "handlers" early on, then I can just change its definition. For example, type Handler = ServerPart Response
and homePage :: Handler
, and then when I add in web-routes I just redefine Handler type Handler = RouteT Sitemap (ServerPartT IO) Response
.
Your editor probably has a search-and-replace feature though, for example in Vim:
:%s/:: ServerPart Response/:: RouteT Sitemap (ServerPartT IO) Response/g