Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added mkRenderRouteInstance' a more general version of mkRenderRouteI…

…nstance
  • Loading branch information...
commit 9c26f86f9115b1e65d0558e1c9861fb2633b74a9 1 parent 895bb76
@piyush-kurur authored
Showing with 12 additions and 4 deletions.
  1. +12 −4 yesod-routes/Yesod/Routes/TH/RenderRoute.hs
View
16 yesod-routes/Yesod/Routes/TH/RenderRoute.hs
@@ -2,6 +2,7 @@
module Yesod.Routes.TH.RenderRoute
( -- ** RenderRoute
mkRenderRouteInstance
+ , mkRenderRouteInstance'
, mkRouteCons
, mkRenderRouteClauses
) where
@@ -89,12 +90,19 @@ mkRenderRouteClauses =
-- | Generate the 'RenderRoute' instance.
--
--- This includes both the 'Route' associated type and the 'renderRoute' method.
--- This function uses both 'mkRouteCons' and 'mkRenderRouteClasses'.
+-- This includes both the 'Route' associated type and the
+-- 'renderRoute' method. This function uses both 'mkRouteCons' and
+-- 'mkRenderRouteClasses'.
mkRenderRouteInstance :: Type -> [Resource Type] -> Q Dec
-mkRenderRouteInstance typ ress = do
+mkRenderRouteInstance = mkRenderRouteInstance' []
+
+-- | A more general version of 'mkRenderRouteInstance' which takes an
+-- additional context.
+
+mkRenderRouteInstance' :: Cxt -> Type -> [Resource Type] -> Q Dec
+mkRenderRouteInstance' cxt typ ress = do
cls <- mkRenderRouteClauses ress
- return $ InstanceD [] (ConT ''RenderRoute `AppT` typ)
+ return $ InstanceD cxt (ConT ''RenderRoute `AppT` typ)
[ DataInstD [] ''Route [typ] (mkRouteCons ress) clazzes
, FunD (mkName "renderRoute") cls
]

3 comments on commit 9c26f86

@gregwebs

Looks pretty straightforward, thanks! I am wondering if the argument position helped you curry. Cxt could be the last argument so that way the function can be called with a trailing empty list.

@piyush-kurur
@piyush-kurur

Sorry I meant mkRenderRouteInstance

Please sign in to comment.
Something went wrong with that request. Please try again.