I have defined my own type called CtrlV:
{-# LANGUAGE TemplateHaskell #-}
import Data.Data (Data, Typeable)
import Happstack.Server (Response, ServerPartT)
import Web.Routes (RouteT)
import Web.Routes.TH (derivePathInfo)
type App = ServerPartT IO
type CtrlV' = RouteT Sitemap App
type CtrlV = CtrlV' Response
data Sitemap = Home | User
deriving (Eq, Ord, Read, Show, Typeable, Data)
$(derivePathInfo ''Sitemap)
I have this function for example:
import Happstack.Foundation
import Happstack.Server (ok, toResponse)
import Web.Routes (showURL)
createResponse :: CtrlV
createResponse = do
url <- showURL Home
ok $ toResponse (show url)
I want to write a test for this function and i want to check Response has the correct result. But i can get Response out of my type CtrlV.
Is there an easy way to achieve this?
To step back from the specifics of the libraries your using, here is how
typeworks:I can declare a type synonym
I know I can use ListOfInts anywhere I would use [Int]:
And now I can use
fandgon both list1 and list2, despite the fact that they are declared with "different" types. Type just declares a synonym for a type, not a new type (which would use thenewtypekeyword).In summary, You can use
CtrlVthe same way you would useCtrlv' Response, which you can use the same way you would useRouteT SiteMap App Response, which you can use the same way you would useRouteT SiteMap (ServerPartT IO) Response, becauseCtrlvisRouteT SiteMap (ServerPartT IO) Response.