@@ -1,6 +1,5 @@
11{-# LANGUAGE LambdaCase #-}
22{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE TupleSections #-}
43{-# LANGUAGE ViewPatterns #-}
54
65-- Module : Gen.Syntax
@@ -26,39 +25,38 @@ import Gen.Text
2625import Gen.Types
2726import Language.Haskell.Exts.Build (app, appFun, infixApp, lamE, listE, name, noBinds, paren, patBind, pvar, sfun, strE, sym,
2827 var)
29−import Language.Haskell.Exts.SrcLoc
3028import Language.Haskell.Exts.Syntax hiding (Alt, Int, Lit)
3129
32−serviceSig :: Name -> Decl
33−serviceSig n = TypeSig noLoc [n] (TyCon "ServiceConfig")
30+serviceSig :: Name () -> Decl ()
31+serviceSig n = TypeSig () [n] (TyCon () "ServiceConfig")
3432
35−serviceDecl :: Service a -> Name -> Decl
36−serviceDecl s n = sfun noLoc n [] (UnGuardedRhs rhs) noBinds
33+serviceDecl :: Service a -> Name () -> Decl ()
34+serviceDecl s n = sfun n [] (UnGuardedRhs () rhs) noBinds
3735 where
3836 rhs = appFun (var "defaultService")
3937 [ app (var "ServiceId") (str (s ^. dId))
4038 , str . stripSuffix "/" $ stripPrefix "https://" (s ^. dRootUrl)
4139 ]
4240
43−scopeSig :: Name -> Text -> Decl
44−scopeSig n v = TypeSig noLoc [n] $
45− TyApp (TyCon "Proxy") $
46− TyPromoted $ PromotedList True
47− [ TyPromoted $ PromotedString (Text.unpack v)
41+scopeSig :: Name () -> Text -> Decl ()
42+scopeSig n v = TypeSig () [n] $
43+ TyApp () (TyCon () "Proxy") $
44+ TyPromoted () $ PromotedList () True
45+ [ TyPromoted () $ PromotedString () (Text.unpack v) (Text.unpack v)
4846 ]
4947
50−scopeDecl :: Name -> Decl
51−scopeDecl n = sfun noLoc n [] (UnGuardedRhs (var "Proxy")) noBinds
48+scopeDecl :: Name () -> Decl ()
49+scopeDecl n = sfun n [] (UnGuardedRhs () (var "Proxy")) noBinds
5250
53−apiAlias :: Name -> [Name] -> Decl
54−apiAlias n ls = TypeDecl noLoc n [] alias
51+apiAlias :: Name () -> [Name ()] -> Decl ()
52+apiAlias n ls = TypeDecl () (DHead () n) alias
5553 where
56− alias = case map (TyCon . UnQual) ls of
57− [] -> unit_tycon
58− x:xs -> foldl' (\l r -> TyInfix l (UnQual (sym ":<|>")) r) x xs
54+ alias = case map (TyCon () . UnQual ()) ls of
55+ [] -> unit_tycon ()
56+ x:xs -> foldl' (\l r -> TyInfix () l ((UnpromotedName () . UnQual ()) (sym ":<|>")) r) x xs
5957
60−verbAlias :: HasDescription a s => a -> Name -> Method Solved -> Decl
61−verbAlias d n m = TypeDecl noLoc n [] $ servantOr meta (catMaybes [down, up])
58+verbAlias :: HasDescription a s => a -> Name () -> Method Solved -> Decl ()
59+verbAlias d n m = TypeDecl () (DHead () n) $ servantOr meta (catMaybes [down, up])
6260 where
6361 meta = path $ metadataAlias m
6462 down = path <$> downloadAlias m
@@ -68,18 +66,18 @@ verbAlias d n m = TypeDecl noLoc n [] $ servantOr meta (catMaybes [down, up])
6866
6967 root = subPaths (d ^. dServicePath) ++ requestPath m (_mPath m)
7068
71−metadataAlias :: Method Solved -> Type
69+metadataAlias :: Method Solved -> Type ()
7270metadataAlias m = servantSub (jsonVerb m) (params ++ media)
7371 where
7472 params = requestQuery m (requestQueryParams m)
7573 media = case _mRequest m of
7674 Nothing -> []
7775 Just b ->
78− [ TyApp (TyApp (TyCon "ReqBody") jsonMedia)
76+ [ TyApp () (TyApp () (TyCon () "ReqBody") jsonMedia)
7977 (tycon (ref b))
8078 ]
8179
82−downloadAlias :: Method Solved -> Maybe Type
80+downloadAlias :: Method Solved -> Maybe (Type ())
8381downloadAlias m
8482 | _mSupportsMediaDownload m = Just download
8583 | otherwise = Nothing
@@ -88,7 +86,7 @@ downloadAlias m
8886
8987 params = requestQuery m . Map.delete "alt" $ requestQueryParams m
9088
91−uploadAlias :: [Type] -> Method Solved -> Maybe Type
89+uploadAlias :: [Type ()] -> Method Solved -> Maybe (Type ())
9290uploadAlias sub m
9391 | _mSupportsMediaUpload m = Just upload
9492 | otherwise = Nothing
@@ -104,16 +102,16 @@ uploadAlias sub m
104102 media = case _mRequest m of
105103 Just b ->
106104 [ multipartParam
107− , TyApp (TyApp (TyCon "MultipartRelated") jsonMedia)
105+ , TyApp () (TyApp () (TyCon () "MultipartRelated") jsonMedia)
108106 (tycon (ref b))
109107 ]
110108
111109 Nothing ->
112110 [ mediaParam
113− , TyCon "AltMedia"
111+ , TyCon () "AltMedia"
114112 ]
115113
116−requestPath :: Method Solved -> Text -> [Type]
114+requestPath :: Method Solved -> Text -> [Type ()]
117115requestPath m = map go . extractPath
118116 where
119117 go (Left t) = sing t
@@ -121,29 +119,29 @@ requestPath m = map go . extractPath
121119 Nothing -> error $ "Unable to find path parameter " ++ show l
122120 Just x -> case c of
123121 Nothing | x ^. iRepeated ->
124− TyApp (TyApp (TyCon "Captures")
122+ TyApp () (TyApp () (TyCon () "Captures")
125123 (sing (local l)))
126124 (terminalType (_type (_pParam x)))
127125
128126 Nothing ->
129− TyApp (TyApp (TyCon "Capture")
127+ TyApp () (TyApp () (TyCon () "Capture")
130128 (sing (local l)))
131129 (terminalType (_type (_pParam x)))
132130
133131 Just y ->
134− TyApp (TyApp (TyApp (TyCon "CaptureMode")
132+ TyApp () (TyApp () (TyApp () (TyCon () "CaptureMode")
135133 (sing (local l)))
136134 (sing y))
137135 (terminalType (_type (_pParam x)))
138136
139−requestQuery :: Method Solved -> Map Local (Param Solved) -> [Type]
137+requestQuery :: Method Solved -> Map Local (Param Solved) -> [Type ()]
140138requestQuery m xs = mapMaybe go $
141139 orderParams fst (Map.toList xs) (_mParameterOrder m)
142140 where
143141 go (k, x) = case _pLocation x of
144142 Query | x ^. iRepeated
145− -> Just $ TyApp (TyApp (TyCon "QueryParams") n) t
146− Query -> Just $ TyApp (TyApp (TyCon "QueryParam") n) t
143+ -> Just $ TyApp () (TyApp () (TyCon () "QueryParams") n) t
144+ Query -> Just $ TyApp () (TyApp () (TyCon () "QueryParam") n) t
147145 Path -> Nothing
148146 where
149147 t = terminalType (_type (_pParam x))
@@ -152,52 +150,47 @@ requestQuery m xs = mapMaybe go $
152150requestQueryParams :: Method a -> Map Local (Param a)
153151requestQueryParams = Map.filter ((/= Path) . _pLocation) . _mParameters
154152
155−servantOr, servantSub :: Type -> [Type] -> Type
156−servantOr = foldl' (\l r -> TyInfix l (UnQual (sym ":<|>")) r)
157−servantSub = foldr' (\l r -> TyInfix l (UnQual (sym ":>")) r)
153+servantOr, servantSub :: Type () -> [Type ()] -> Type ()
154+servantOr = foldl' (\l r -> TyInfix () l ((UnpromotedName () . UnQual ()) (sym ":<|>")) r)
155+servantSub = foldr' (\l r -> TyInfix () l ((UnpromotedName () . UnQual ()) (sym ":>")) r)
158156
159−jsonVerb :: Method a -> Type
157+jsonVerb :: Method a -> Type ()
160158jsonVerb m =
161− TyApp (TyApp (httpMethod m) jsonMedia)
162− $ maybe (TyCon "()") (tycon . ref) (_mResponse m)
159+ TyApp () (TyApp () (httpMethod m) jsonMedia)
160+ $ maybe (TyCon () "()") (tycon . ref) (_mResponse m)
163161
164−downloadVerb :: Method a -> Type
162+downloadVerb :: Method a -> Type ()
165163downloadVerb m =
166− TyApp (TyApp (httpMethod m) streamMedia)
167− (TyCon "Stream")
164+ TyApp () (TyApp () (httpMethod m) streamMedia)
165+ (TyCon () "Stream")
168166
169−httpMethod :: Method a -> Type
170−httpMethod = TyCon . unqual . Text.unpack . Text.toTitle . _mHttpMethod
167+httpMethod :: Method a -> Type ()
168+httpMethod = TyCon () . unqual . Text.unpack . Text.toTitle . _mHttpMethod
171169
172−subPaths :: Text -> [Type]
170+subPaths :: Text -> [Type ()]
173171subPaths = map sing . filter (not . Text.null) . Text.split (== '/')
174172
175−jsonMedia, streamMedia :: Type
173+jsonMedia, streamMedia :: Type ()
176174jsonMedia = tylist ["JSON"]
177175streamMedia = tylist ["OctetStream"]
178176
179−downloadParam :: Type
177+downloadParam :: Type ()
180178downloadParam =
181− TyApp (TyApp (TyCon "QueryParam") (sing "alt"))
182− (TyCon "AltMedia")
179+ TyApp () (TyApp () (TyCon () "QueryParam") (sing "alt"))
180+ (TyCon () "AltMedia")
183181
184−mediaParam :: Type
182+mediaParam :: Type ()
185183mediaParam =
186− TyApp (TyApp (TyCon "QueryParam") (sing "uploadType"))
187− (TyCon "AltMedia")
184+ TyApp () (TyApp () (TyCon () "QueryParam") (sing "uploadType"))
185+ (TyCon () "AltMedia")
188186
189−multipartParam :: Type
187+multipartParam :: Type ()
190188multipartParam =
191− TyApp (TyApp (TyCon "QueryParam") (sing "uploadType"))
192− (TyCon "Multipart")
189+ TyApp () (TyApp () (TyCon () "QueryParam") (sing "uploadType"))
190+ (TyCon () "Multipart")
193191
194−metadataPat, downloadPat, uploadPat :: Method a -> Pat
195−metadataPat = pattern 1
196−downloadPat = pattern 2
197−uploadPat = pattern 3
198−
199−pattern :: Integer -> Method a -> Pat
200−pattern n m = case (n, down, up) of
192+pattern' :: Integer -> Method a -> Pat ()
193+pattern' n m = case (n, down, up) of
201194 (1, True, True) -> infixOr go (infixOr wild wild)
202195 (2, True, True) -> infixOr wild (infixOr go wild)
203196 (_, True, True) -> infixOr wild (infixOr wild go)
@@ -214,51 +207,57 @@ pattern n m = case (n, down, up) of
214207 up = _mSupportsMediaUpload m
215208
216209 go = pvar "go"
217− wild = PWildCard
210+ wild = PWildCard ()
211+
212+ infixOr l = PInfixApp () l (UnQual () (sym ":<|>"))
213+
214+metadataPat, downloadPat, uploadPat :: Method a -> Pat ()
215+metadataPat = pattern' 1
216+downloadPat = pattern' 2
217+uploadPat = pattern' 3
218218
219− infixOr l r = PInfixApp l (UnQual (sym ":<|>")) r
220219
221220downloadDecl :: Global
222221 -> Prefix
223− -> Name
224− -> Name
222+ -> Name ()
223+ -> Name ()
225224 -> [Local]
226225 -> Method Solved
227− -> Decl
226+ -> Decl ()
228227downloadDecl n pre api url fs m =
229− googleRequestDecl ty [rs, ss] [alt] pre api url m pat prec
228+ googleRequestDecl (TyParen () ty) [rs, ss] [alt] pre api url m pat prec
230229 where
231− ty = TyApp (TyCon "MediaDownload") (tycon n)
230+ ty = TyApp () (TyCon () "MediaDownload") (tycon n)
232231
233− rs = InsType noLoc (TyApp (TyCon "Rs") ty) (TyCon "Stream")
232+ rs = InsType () (TyApp () (TyCon () "Rs") ty) (TyCon () "Stream")
234233
235− ss = InsType noLoc (TyApp (TyCon "Scopes") ty) $
236− TyApp (TyCon "Scopes") (tycon n)
234+ ss = InsType () (TyApp () (TyCon () "Scopes") ty) $
235+ TyApp () (TyCon () "Scopes") (tycon n)
237236
238237 alt = app (var "Just") (var "AltMedia")
239238 pat = downloadPat m
240239
241− prec = PApp (UnQual "MediaDownload")
242− [ PRec (UnQual (dname' n)) [PFieldWildcard | not (null fs)]
240+ prec = PApp () (UnQual () "MediaDownload")
241+ [ PRec () (UnQual () (dname' n)) [PFieldWildcard () | not (null fs)]
243242 ]
244243
245244uploadDecl :: Global
246245 -> Prefix
247− -> Name
248− -> Name
246+ -> Name ()
247+ -> Name ()
249248 -> [Local]
250249 -> Method Solved
251− -> Decl
250+ -> Decl ()
252251uploadDecl n pre api url fs m =
253− googleRequestDecl ty [rs, ss] extras pre api url m pat prec
252+ googleRequestDecl (TyParen () ty) [rs, ss] extras pre api url m pat prec
254253 where
255− ty = TyApp (TyCon "MediaUpload") (tycon n)
254+ ty = TyApp () (TyCon () "MediaUpload") (tycon n)
256255
257− rs = InsType noLoc (TyApp (TyCon "Rs") ty) $
258− maybe unit_tycon (tycon . ref) (_mResponse m)
256+ rs = InsType () (TyApp () (TyCon () "Rs") ty) $
257+ maybe (unit_tycon ()) (tycon . ref) (_mResponse m)
259258
260− ss = InsType noLoc (TyApp (TyCon "Scopes") ty) $
261− TyApp (TyCon "Scopes") (tycon n)
259+ ss = InsType () (TyApp () (TyCon () "Scopes") ty) $
260+ TyApp () (TyCon () "Scopes") (tycon n)
262261
263262 extras = maybeToList alt ++ [upl] ++ payload ++ [var media]
264263 where
@@ -276,30 +275,32 @@ uploadDecl n pre api url fs m =
276275
277276 pat = uploadPat m
278277
279− prec = PApp (UnQual "MediaUpload")
280− [ PRec (UnQual (dname' n)) [PFieldWildcard | not (null fs)]
281− , PVar media
278+ prec = PApp () (UnQual () "MediaUpload")
279+ [ PRec () (UnQual () (dname' n)) [PFieldWildcard () | not (null fs)]
280+ , PVar () media
282281 ]
283282
284283 media = name "body"
285284
286285requestDecl :: Global
287286 -> Prefix
288− -> Name
289− -> Name
287+ -> Name ()
288+ -> Name ()
290289 -> [Local]
291290 -> Method Solved
292− -> Decl
291+ -> Decl ()
293292requestDecl n pre api url fs m =
294293 googleRequestDecl (tycon n) [rs, ss] extras pre api url m pat prec
295294 where
296− rs = InsType noLoc (TyApp (TyCon "Rs") (tycon n)) $
297− maybe unit_tycon (tycon . ref) (_mResponse m)
295+ rs :: InstDecl ()
296+ rs = InsType () (TyApp () (TyCon () "Rs") (tycon n)) $
297+ maybe (unit_tycon ()) (tycon . ref) (_mResponse m)
298298
299− ss = InsType noLoc (TyApp (TyCon "Scopes") (tycon n)) $
300− TyPromoted $
301− PromotedList True $
302− map (TyPromoted . PromotedString . Text.unpack) (_mScopes m)
299+ ss :: InstDecl ()
300+ ss = InsType () (TyApp () (TyCon () "Scopes") (tycon n)) $
301+ TyPromoted () $
302+ PromotedList () True $
303+ map (\m' -> TyPromoted () (PromotedString () (Text.unpack m') "Scopes")) (_mScopes m)
303304
304305 extras = catMaybes [alt, payload]
305306 where
@@ -312,35 +313,35 @@ requestDecl n pre api url fs m =
312313
313314 pat = metadataPat m
314315
315− prec = PRec (UnQual (dname' n)) [PFieldWildcard | not (null fs)]
316+ prec = PRec () (UnQual () (dname' n)) [PFieldWildcard () | not (null fs)]
316317
317−googleRequestDecl :: Type
318− -> [InstDecl]
319− -> [Exp]
318+googleRequestDecl :: Type ()
319+ -> [InstDecl ()]
320+ -> [Exp ()]
320321 -> Prefix
321− -> Name
322− -> Name
322+ -> Name ()
323+ -> Name ()
323324 -> Method Solved
324− -> Pat
325− -> Pat
326− -> Decl
325+ -> Pat ()
326+ -> Pat ()
327+ -> Decl ()
327328googleRequestDecl n assoc extras pre api url m pat prec =
328− InstDecl noLoc Nothing [] [] (unqual "GoogleRequest") [n] (assoc ++ [request])
329+ InstDecl () Nothing (instrule "GoogleRequest" n) (Just (assoc ++ [request]))
329330 where
330− request = InsDecl (FunBind [match])
331+ request = InsDecl () (FunBind () [match])
331332
332− match = Match noLoc (name "requestClient") [prec] Nothing rhs (Just decls)
333+ match = Match () (name "requestClient") [prec] rhs (Just decls)
333334
334− decls = BDecls
335− [ patBind noLoc pat $
336− appFun (var "buildClient") $
337− [ ExpTypeSig noLoc (var "Proxy") $
338− TyApp (TyCon "Proxy") (TyCon (UnQual api))
335+ decls = BDecls ()
336+ [ patBind pat $
337+ appFun (var "buildClient")
338+ [ ExpTypeSig () (var "Proxy") $
339+ TyApp () (TyCon () "Proxy") (TyCon () (UnQual () api))
339340 , var "mempty"
340341 ]
341342 ]
342343
343− rhs = UnGuardedRhs . appFun (var "go") $ map go fs ++ extras ++ [var url]
344+ rhs = UnGuardedRhs () . appFun (var "go") $ map go fs ++ extras ++ [var url]
344345 where
345346 go l = case Map.lookup l ps of
346347 Just p | _pLocation p == Query
@@ -365,16 +366,15 @@ googleRequestDecl n assoc extras pre api url m pat prec =
365366 . nub
366367 $ map fst (rights (extractPath (_mPath m))) ++ _mParameterOrder m
367368
368−jsonDecls :: Global -> Prefix -> Map Local Solved -> [Decl]
369+jsonDecls :: Global -> Prefix -> Map Local Solved -> [Decl ()]
369370jsonDecls g p (Map.toList -> rs) = [from', to']
370371 where
371− from' = InstDecl noLoc Nothing [] [] (unqual "FromJSON") [tycon g]
372+ from' = InstDecl () Nothing (instrule "FromJSON" (tycon g)) (Just
372373 [ funD "parseJSON" $
373374 app (app (var "withObject") (dstr g)) $
374− lamE noLoc [pvar "o"] $
375+ lamE [pvar "o"] $
375376 ctorE g (map decode rs)
376− ]
377−
377+ ])
378378 decode (l, s)
379379 | _additional s = app (var "parseJSONObject") (var "o")
380380 | Just x <- def s = defJS l x
@@ -384,15 +384,15 @@ jsonDecls g p (Map.toList -> rs) = [from', to']
384384
385385 to' = case rs of
386386 [(k, v)] | _additional v ->
387− InstDecl noLoc Nothing [] [] (unqual "ToJSON") [tycon g]
387+ InstDecl () Nothing (instrule "ToJSON" (tycon g)) (Just
388388 [ funD "toJSON" $
389389 infixApp (var "toJSON") "." (var (fname p k))
390− ]
390+ ])
391391
392392 _ ->
393− InstDecl noLoc Nothing [] [] (unqual "ToJSON") [tycon g]
393+ InstDecl () Nothing (instrule "ToJSON" (tycon g)) (Just
394394 [ wildcardD "toJSON" g omit emptyObj (map encode rs)
395− ]
395+ ])
396396
397397 omit = app (var "object")
398398 . app (var "catMaybes")
@@ -410,81 +410,99 @@ jsonDecls g p (Map.toList -> rs) = [from', to']
410410
411411wildcardD :: String
412412 -> Global
413− -> ([Exp] -> Exp)
414− -> Exp
415− -> [Exp]
416− -> InstDecl
413+ -> ([Exp ()] -> Exp ())
414+ -> Exp ()
415+ -> [Exp ()]
416+ -> InstDecl ()
417417wildcardD f n enc x = \case
418418 [] -> constD f x
419− xs -> InsDecl (FunBind [match prec xs])
419+ xs -> InsDecl () (FunBind () [match prec xs])
420420 where
421421 match p es =
422− Match noLoc (name f) [p] Nothing (UnGuardedRhs (enc es)) noBinds
422+ Match () (name f) [p] (UnGuardedRhs () (enc es)) noBinds
423423
424− prec = PRec (UnQual (dname' n)) [PFieldWildcard]
424+ prec = PRec () (UnQual () (dname' n)) [PFieldWildcard ()]
425425
426−defJS :: Local -> Exp -> Exp
427−defJS n x = infixApp (infixApp (var "o") ".:?" (fstr n)) ".!=" x
426+defJS :: Local -> Exp () -> Exp ()
427+defJS n = infixApp (infixApp (var "o") ".:?" (fstr n)) ".!="
428428
429−reqJS :: Local -> Exp
429+reqJS :: Local -> Exp ()
430430reqJS = infixApp (var "o") ".:" . fstr
431431
432−optJS :: Local -> Exp
432+optJS :: Local -> Exp ()
433433optJS = infixApp (var "o") ".:?" . fstr
434434
435−funD :: String -> Exp -> InstDecl
436−funD f = InsDecl . patBind noLoc (pvar (name f))
435+funD :: String -> Exp () -> InstDecl ()
436+funD f = InsDecl () . patBind (pvar (name f))
437437
438−constD :: String -> Exp -> InstDecl
439−constD f x = InsDecl $
440− sfun noLoc (name f) [] (UnGuardedRhs (app (var "const") x)) noBinds
438+constD :: String -> Exp () -> InstDecl ()
439+constD f x = InsDecl () $
440+ sfun (name f) [] (UnGuardedRhs () (app (var "const") x)) noBinds
441441
442−ctorE :: Global -> [Exp] -> Exp
442+ctorE :: Global -> [Exp ()] -> Exp ()
443443ctorE n = seqE (var (dname' n)) . map paren
444444
445−seqE :: Exp -> [Exp] -> Exp
445+seqE :: Exp () -> [Exp ()] -> Exp ()
446446seqE l [] = app (var "pure") l
447447seqE l (r:rs) = infixApp l "<$>" (infixE r "<*>" rs)
448448
449−objDecl :: Global -> Prefix -> [Derive] -> Map Local Solved -> Decl
449+objDecl :: Global -> Prefix -> [Derive] -> Map Local Solved -> Decl ()
450450objDecl n p ds rs =
451− DataDecl noLoc arity [] (dname n) [] [conDecl (dname' n) p rs] (der ds)
451+ DataDecl () arity Nothing (DHead () (dname n)) [conDecl (dname' n) p rs] [der ds]
452452 where
453− arity | Map.size rs == 1 = NewType
454− | otherwise = DataType
455−
456− der = map ((,[]) . unqual . drop 1 . show)
457−
458−conDecl :: Name -> Prefix -> Map Local Solved -> QualConDecl
459−conDecl n p rs = QualConDecl noLoc [] [] body
453+ arity | Map.size rs == 1 = NewType ()
454+ | otherwise = DataType ()
455+
456+ der = Deriving () Nothing . map (unqualrule . drop 1 . show)
457+
458+-- decl =
459+-- DataDecl
460+-- ()
461+-- (DataType ())
462+-- Nothing
463+-- (DHead () (Ident () "AboutGet"))
464+-- [QualConDecl () Nothing Nothing (ConDecl () (Ident () "AboutGet'") [])]
465+-- [ Deriving
466+-- ()
467+-- Nothing
468+-- [ IRule () Nothing Nothing (IHCon () (UnQual () (Ident () "Eq")))
469+-- , IRule () Nothing Nothing (IHCon () (UnQual () (Ident () "Show")))
470+-- , IRule () Nothing Nothing (IHCon () (UnQual () (Ident () "Data")))
471+-- , IRule () Nothing Nothing (IHCon () (UnQual () (Ident () "Typeable")))
472+-- , IRule () Nothing Nothing (IHCon () (UnQual () (Ident () "Generic")))
473+-- ]
474+-- ]
475+
476+conDecl :: Name () -> Prefix -> Map Local Solved -> QualConDecl ()
477+conDecl n p rs = QualConDecl () Nothing Nothing body
460478 where
461479 body = case Map.toList rs of
462− [] -> ConDecl n []
463− [x] -> RecDecl n [field internalType x]
464− xs -> RecDecl n (map (field (strict . internalType)) xs)
480+ [] -> ConDecl () n []
481+ [x] -> RecDecl () n [field internalType x]
482+ xs -> RecDecl () n (map (field (strict . internalType)) xs)
465483
466− field f (l, v) = ([fname p l], f (_type v))
484+ field f (l, v) = FieldDecl () [fname p l] (f (_type v))
467485
468−ctorSig :: Global -> Map Local Solved -> Decl
469−ctorSig n rs = TypeSig noLoc [cname n] ts
486+ctorSig :: Global -> Map Local Solved -> Decl ()
487+ctorSig n rs = TypeSig () [cname n] ts
470488 where
471− ts = foldr' TyFun (TyCon (UnQual (dname n))) ps
489+ ts = foldr' (TyFun ()) (TyCon () (UnQual () (dname n))) ps
472490 ps = parameters (Map.elems rs)
473491
474−ctorDecl :: Global -> Prefix -> Map Local Solved -> Decl
475−ctorDecl n p rs = sfun noLoc c ps (UnGuardedRhs rhs) noBinds
492+ctorDecl :: Global -> Prefix -> Map Local Solved -> Decl ()
493+ctorDecl n p rs = sfun c ps (UnGuardedRhs () rhs) noBinds
476494 where
477495 c = cname n
478496 d = dname' n
479497
480498 rhs | Map.null rs = var d
481− | otherwise = RecConstr (UnQual d) $
499+ | otherwise = RecConstr () (UnQual () d) $
482500 map (uncurry (fieldUpdate p)) (Map.toList rs)
483501
484502 ps = map (pname p) . Map.keys $ Map.filter parameter rs
485503
486−fieldUpdate :: Prefix -> Local -> Solved -> FieldUpdate
487−fieldUpdate p l s = FieldUpdate (UnQual (fname p l)) rhs
504+fieldUpdate :: Prefix -> Local -> Solved -> FieldUpdate ()
505+fieldUpdate p l s = FieldUpdate () (UnQual () (fname p l)) rhs
488506 where
489507 rhs | Just x <- def s, s ^. iRepeated = listE [x]
490508 | Just x <- def s = x
@@ -494,26 +512,26 @@ fieldUpdate p l s = FieldUpdate (UnQual (fname p l)) rhs
494512
495513 v = var (pname p l)
496514
497−lensSig :: Global -> Prefix -> Local -> Solved -> Decl
498−lensSig n p l s = TypeSig noLoc [lname p l] $
499− TyApp (TyApp (TyCon "Lens'") (tycon n))
515+lensSig :: Global -> Prefix -> Local -> Solved -> Decl ()
516+lensSig n p l s = TypeSig () [lname p l] $
517+ TyApp () (TyApp () (TyCon () "Lens'") (tycon n))
500518 (externalType (_type s))
501519
502−lensDecl :: Prefix -> Local -> Solved -> Decl
503−lensDecl p l s = sfun noLoc (lname p l) [] (UnGuardedRhs rhs) noBinds
520+lensDecl :: Prefix -> Local -> Solved -> Decl ()
521+lensDecl p l s = sfun (lname p l) [] (UnGuardedRhs () rhs) noBinds
504522 where
505523 f = fname p l
506524 t = _type s
507525
508526 rhs = mapping t $
509527 app (app (var "lens") (var f))
510− (paren (lamE noLoc [pvar "s", pvar "a"]
511− (RecUpdate (var "s") [FieldUpdate (UnQual f) (var "a")])))
528+ (paren (lamE [pvar "s", pvar "a"]
529+ (RecUpdate () (var "s") [FieldUpdate () (UnQual () f) (var "a")])))
512530
513−parameters :: [Solved] -> [Type]
531+parameters :: [Solved] -> [Type ()]
514532parameters = map (externalType . _type) . filter parameter
515533
516−def :: Solved -> Maybe Exp
534+def :: Solved -> Maybe (Exp ())
517535def s
518536 | Just x <- s ^. iDefault = Just (go x (_prefix s) (_schema s))
519537 | otherwise = Nothing
@@ -527,88 +545,88 @@ def s
527545
528546 lit = var . name . Text.unpack
529547
530−terminalType :: TType -> Type
548+terminalType :: TType -> Type ()
531549terminalType = internalType . go
532550 where
533551 go (TMaybe x) = go x
534552 go (TList x) = go x
535553 go x = x
536554
537−externalType :: TType -> Type
555+externalType :: TType -> Type ()
538556externalType = \case
539557 TType r -> tycon r
540558 TMaybe t@TList {} -> externalType t
541− TMaybe t -> TyApp (TyCon "Maybe") (externalType t)
542− TList t -> TyList (externalType t)
559+ TMaybe t -> TyApp () (TyCon () "Maybe") (externalType t)
560+ TList t -> TyList () (externalType t)
543561 TLit l -> externalLit l
544562 TMap k v ->
545− TyApp (TyApp (TyCon "HashMap") (externalType k)) (externalType (require v))
563+ TyApp () (TyApp () (TyCon () "HashMap") (externalType k)) (externalType (require v))
546564
547−internalType :: TType -> Type
565+internalType :: TType -> Type ()
548566internalType = \case
549567 TType r -> tycon r
550− TMaybe t -> TyApp (TyCon "Maybe") (internalType t)
551− TList t -> TyList (internalType t)
568+ TMaybe t -> TyApp () (TyCon () "Maybe") (internalType t)
569+ TList t -> TyList () (internalType t)
552570 TLit l -> internalLit l
553571 TMap k v ->
554− TyApp (TyApp (TyCon "HashMap") (internalType k)) (internalType (require v))
572+ TyApp () (TyApp () (TyCon () "HashMap") (internalType k)) (internalType (require v))
555573
556−externalLit :: Lit -> Type
574+externalLit :: Lit -> Type ()
557575externalLit = \case
558− Text -> TyCon "Text"
559− Bool -> TyCon "Bool"
560− Time -> TyCon "TimeOfDay"
561− Date -> TyCon "Day"
562− DateTime -> TyCon "UTCTime"
563− Nat -> TyCon "Natural"
564− Float -> TyCon "Double"
565− Double -> TyCon "Double"
566− Byte -> TyCon "ByteString"
567− UInt32 -> TyCon "Word32"
568− UInt64 -> TyCon "Word64"
569− Int32 -> TyCon "Int32"
570− Int64 -> TyCon "Int64"
571− Alt t -> TyCon (unqual (Text.unpack t))
572− RqBody -> TyCon "RequestBody"
573− RsBody -> TyCon "Stream"
574− JSONValue -> TyCon "JSONValue"
575− GFieldMask -> TyCon "GFieldMask"
576− GDuration -> TyCon "Scientific"
577−
578−internalLit :: Lit -> Type
576+ Text -> TyCon () "Text"
577+ Bool -> TyCon () "Bool"
578+ Time -> TyCon () "TimeOfDay"
579+ Date -> TyCon () "Day"
580+ DateTime -> TyCon () "UTCTime"
581+ Nat -> TyCon () "Natural"
582+ Float -> TyCon () "Double"
583+ Double -> TyCon () "Double"
584+ Byte -> TyCon () "ByteString"
585+ UInt32 -> TyCon () "Word32"
586+ UInt64 -> TyCon () "Word64"
587+ Int32 -> TyCon () "Int32"
588+ Int64 -> TyCon () "Int64"
589+ Alt t -> TyCon () (unqual (Text.unpack t))
590+ RqBody -> TyCon () "RequestBody"
591+ RsBody -> TyCon () "Stream"
592+ JSONValue -> TyCon () "JSONValue"
593+ GFieldMask -> TyCon () "GFieldMask"
594+ GDuration -> TyCon () "Scientific"
595+
596+internalLit :: Lit -> Type ()
579597internalLit = \case
580− Text -> TyCon "Text"
581− Bool -> TyCon "Bool"
582− Time -> TyCon "Time'"
583− Date -> TyCon "Date'"
584− DateTime -> TyCon "DateTime'"
585− Nat -> TyApp (TyCon "Textual") (TyCon "Nat")
586− Float -> TyApp (TyCon "Textual") (TyCon "Double")
587− Double -> TyApp (TyCon "Textual") (TyCon "Double")
588− Byte -> TyCon "Bytes"
589− UInt32 -> TyApp (TyCon "Textual") (TyCon "Word32")
590− UInt64 -> TyApp (TyCon "Textual") (TyCon "Word64")
591− Int32 -> TyApp (TyCon "Textual") (TyCon "Int32")
592− Int64 -> TyApp (TyCon "Textual") (TyCon "Int64")
593− Alt t -> TyCon (unqual (Text.unpack t))
594− RqBody -> TyCon "RequestBody"
595− RsBody -> TyCon "Stream"
596− JSONValue -> TyCon "JSONValue"
597− GFieldMask -> TyCon "GFieldMask"
598− GDuration -> TyCon "GDuration"
599−
600−mapping :: TType -> Exp -> Exp
598+ Text -> TyCon () "Text"
599+ Bool -> TyCon () "Bool"
600+ Time -> TyCon () "Time'"
601+ Date -> TyCon () "Date'"
602+ DateTime -> TyCon () "DateTime'"
603+ Nat -> TyApp () (TyCon () "Textual") (TyCon () "Nat")
604+ Float -> TyApp () (TyCon () "Textual") (TyCon () "Double")
605+ Double -> TyApp () (TyCon () "Textual") (TyCon () "Double")
606+ Byte -> TyCon () "Bytes"
607+ UInt32 -> TyApp () (TyCon () "Textual") (TyCon () "Word32")
608+ UInt64 -> TyApp () (TyCon () "Textual") (TyCon () "Word64")
609+ Int32 -> TyApp () (TyCon () "Textual") (TyCon () "Int32")
610+ Int64 -> TyApp () (TyCon () "Textual") (TyCon () "Int64")
611+ Alt t -> TyCon () (unqual (Text.unpack t))
612+ RqBody -> TyCon () "RequestBody"
613+ RsBody -> TyCon () "Stream"
614+ JSONValue -> TyCon () "JSONValue"
615+ GFieldMask -> TyCon () "GFieldMask"
616+ GDuration -> TyCon () "GDuration"
617+
618+mapping :: TType -> Exp () -> Exp ()
601619mapping t e = infixE e "." (go t)
602620 where
603621 go = \case
604− TMaybe x@(TList {}) -> var "_Default" : go x
605− TMaybe x -> nest (go x)
606− x -> maybeToList (iso x)
622+ TMaybe x@TList {} -> var "_Default" : go x
623+ TMaybe x -> nest (go x)
624+ x -> maybeToList (iso x)
607625
608626 nest [] = []
609627 nest (x:xs) = [app (var "mapping") (infixE x "." xs)]
610628
611−iso :: TType -> Maybe Exp
629+iso :: TType -> Maybe (Exp ())
612630iso = \case
613631 TList {} -> Just (var "_Coerce")
614632 TMap {} -> Just (var "_Coerce")
@@ -630,27 +648,33 @@ require :: TType -> TType
630648require (TMaybe t) = t
631649require t = t
632650
633−strict :: Type -> Type
634−strict = TyBang BangedTy . \case
635− t@TyApp{} -> TyParen t
651+strict :: Type () -> Type ()
652+strict = TyBang () (BangedTy ()) (NoUnpackPragma ()) . \case
653+ t@TyApp{} -> TyParen () t
636654 t -> t
637655
638−sing :: Text -> Type
639−sing = TyCon . unqual . Text.unpack . flip mappend "\"" . mappend "\""
656+sing :: Text -> Type ()
657+sing = TyCon () . unqual . Text.unpack . flip mappend "\"" . mappend "\""
640658
641−tylist :: [Text] -> Type
642−tylist xs = TyCon . UnQual . name . Text.unpack $
659+tylist :: [Text] -> Type ()
660+tylist xs = TyCon () . UnQual () . name . Text.unpack $
643661 "'[" <> Text.intercalate ", " xs <> "]"
644662
645−tycon :: Global -> Type
646−tycon = TyCon . UnQual . dname
663+tycon :: Global -> Type ()
664+tycon = TyCon () . UnQual () . dname
665+
666+unqual :: String -> QName ()
667+unqual = UnQual () . name
668+
669+unqualrule :: String -> InstRule ()
670+unqualrule = IRule () Nothing Nothing . IHCon () . unqual
647671
648−unqual :: String -> QName
649−unqual = UnQual . name
672+instrule :: String -> Type () -> InstRule ()
673+instrule n t = IRule () Nothing Nothing (IHApp () (IHCon () (unqual n)) t)
650674
651−infixE :: Exp -> QOp -> [Exp] -> Exp
675+infixE :: Exp () -> QOp () -> [Exp ()] -> Exp ()
652676infixE l _ [] = l
653677infixE l o (r:rs) = infixE (infixApp l o r) o rs
654678
655−str :: Text -> Exp
679+str :: Text -> Exp ()
656680str = strE . Text.unpack