Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

make Route a data family, so the typechecker can infer Site types fro…

…m Route types
  • Loading branch information...
commit f3afdfeea2b2cac40051ce1ad795e798faf96be6 1 parent 125090a
softmechanics authored November 09, 2010
7  Yesod/Dispatch.hs
@@ -138,8 +138,9 @@ mkYesodGeneral name args clazzes isSub res = do
138 138
     th <- mapM (thResourceFromResource arg) res -- FIXME now we cannot have multi-nested subsites
139 139
     w' <- createRoutes th
140 140
     let routesName = mkName $ name ++ "Route"
141  
-    let w = DataD [] routesName [] w' [''Show, ''Read, ''Eq]
142  
-    let x = TySynInstD ''Route [arg] $ ConT routesName
  141
+    let route = ConT ''Route `AppT` arg
  142
+    let w = DataInstD [] ''Route [arg] w' [''Show, ''Read, ''Eq]
  143
+    let x = TySynD routesName (map PlainTV args') route
143 144
 
144 145
     parse' <- createParse th
145 146
     parse'' <- newName "parse"
@@ -164,7 +165,7 @@ mkYesodGeneral name args clazzes isSub res = do
164 165
     let y = InstanceD ctx ytyp
165 166
                 [ FunD (mkName yfunc) [Clause [] (NormalB site') []]
166 167
                 ]
167  
-    return ([w, x], [y])
  168
+    return ([w,x], [y])
168 169
 
169 170
 isStatic :: Piece -> Bool
170 171
 isStatic StaticPiece{} = True
2  Yesod/Handler.hs
@@ -120,7 +120,7 @@ import Yesod.Content
120 120
 #endif
121 121
 
122 122
 -- | The type-safe URLs associated with a site argument.
123  
-type family Route a
  123
+data family Route a
124 124
 
125 125
 data HandlerData sub master = HandlerData
126 126
     { handlerRequest :: Request
3  Yesod/Helpers/Crud.hs
@@ -7,7 +7,8 @@
7 7
 module Yesod.Helpers.Crud
8 8
     ( Item (..)
9 9
     , Crud (..)
10  
-    , CrudRoute (..)
  10
+    , CrudRoute
  11
+    , Route (..)
11 12
     , defaultCrud
12 13
     ) where
13 14
 
9  Yesod/Helpers/Static.hs
@@ -27,7 +27,8 @@
27 27
 module Yesod.Helpers.Static
28 28
     ( -- * Subsite
29 29
       Static (..)
30  
-    , StaticRoute (..)
  30
+    , StaticRoute
  31
+    , Route (..)
31 32
       -- * Lookup files in filesystem
32 33
     , fileLookupDir
33 34
     , staticFiles
@@ -74,10 +75,10 @@ data Static = Static
74 75
 -- would generate a url such as 'http://site.com/static/thumb001.jpg?foo=5&bar=choc'
75 76
 -- The StaticRoute constructor can be used when url's cannot be statically generated at compile-time.
76 77
 -- E.g. When generating image galleries.
77  
-data StaticRoute = StaticRoute [String] [(String, String)]
78  
-    deriving (Eq, Show, Read)
79 78
 
80  
-type instance Route Static = StaticRoute
  79
+data instance Route Static = StaticRoute [String] [(String, String)]
  80
+    deriving (Eq, Show, Read)
  81
+type StaticRoute = Route Static
81 82
 
82 83
 instance YesodSubSite Static master where
83 84
     getSubSite = Site
4  Yesod/Yesod.hs
@@ -11,6 +11,7 @@ module Yesod.Yesod
11 11
       Yesod (..)
12 12
     , YesodSite (..)
13 13
     , YesodSubSite (..)
  14
+    , YesodSubRoute (..)
14 15
       -- ** Persistence
15 16
     , YesodPersist (..)
16 17
     , module Database.Persist
@@ -82,6 +83,9 @@ type Method = String
82 83
 class Eq (Route s) => YesodSubSite s y where
83 84
     getSubSite :: Site (Route s) (Method -> Maybe (GHandler s y ChooseRep))
84 85
 
  86
+class YesodSubRoute s y where
  87
+    subRoute :: Route s -> Route y
  88
+
85 89
 -- | Define settings for a Yesod applications. The only required setting is
86 90
 -- 'approot'; other than that, there are intelligent defaults.
87 91
 class Eq (Route a) => Yesod a where

0 notes on commit f3afdfe

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