@@ -32,7 +32,7 @@ import Language.Haskell.Exts.SrcLoc
3232import Language.Haskell.Exts.Syntax hiding (Int, Lit)
3333
3434urlSig :: Name -> Decl
35−urlSig n = TypeSig noLoc [n] (tycon "BaseUrl")
35+urlSig n = TypeSig noLoc [n] (TyCon "BaseUrl")
3636
3737urlDecl :: Name -> String -> Text -> Integer -> Decl
3838urlDecl n s u p = sfun noLoc n [] (UnGuardedRhs rhs) noBinds
@@ -40,10 +40,10 @@ urlDecl n s u p = sfun noLoc n [] (UnGuardedRhs rhs) noBinds
4040 rhs = appFun (var "BaseUrl") [var (name s), str u, intE p]
4141
4242 -- type API = :<|> ...
43−apiAlias :: Name -> [Global] -> Decl
43+apiAlias :: Name -> [Name] -> Decl
4444apiAlias n ls = TypeDecl noLoc n [] alias
4545 where
46− alias = case map tycon ls of
46+ alias = case map (TyCon . UnQual) ls of
4747 [] -> unit_tycon
4848 x:xs -> foldl' (\l r -> TyInfix l (UnQual (sym ":<|>")) r) x xs
4949
@@ -67,7 +67,7 @@ verbAlias n m = TypeDecl noLoc n [] alias
6767 , c == '{'
6868 , Just k <- Map.lookup (toKey (Text.init t)) params
6969 , _pLocation k == Path
70− = TyApp (TyApp (tycon "Capture")
70+ = TyApp (TyApp (TyCon "Capture")
7171 (sing (Text.init t)))
7272 (terminalType (_type (_pParam k)))
7373 | otherwise = sing x
@@ -81,8 +81,8 @@ verbAlias n m = TypeDecl noLoc n [] alias
8181 n = sing (local k)
8282 in case _pLocation x of
8383 Query | x ^. iRepeated
84− -> Just $ TyApp (TyApp (tycon "QueryParams") n) t
85− Query -> Just $ TyApp (TyApp (tycon "QueryParam") n) t
84+ -> Just $ TyApp (TyApp (TyCon "QueryParams") n) t
85+ Query -> Just $ TyApp (TyApp (TyCon "QueryParam") n) t
8686 Path -> Nothing
8787
8888 params = _mParameters m
@@ -91,8 +91,8 @@ verbAlias n m = TypeDecl noLoc n [] alias
9191 verb = TyApp (TyApp meth typ) res
9292 where
9393 meth = TyCon . unqual . Text.unpack $ Text.toTitle (_mHttpMethod m)
94− typ = tycon "'[JSON]"
95− res = maybe (tycon "()") (tycon . ref) (_mResponse m)
94+ typ = TyCon "'[JSON]"
95+ res = maybe (TyCon "()") (tycon . ref) (_mResponse m)
9696
9797requestDecl :: Global
9898 -> Prefix
@@ -108,7 +108,7 @@ requestDecl n p api url fs m =
108108 , requestWithRoute
109109 ]
110110 where
111− response = InsType noLoc (TyApp (tycon "Rs") (tycon n)) $
111+ response = InsType noLoc (TyApp (TyCon "Rs") (tycon n)) $
112112 maybe unit_tycon (tycon . ref) (_mResponse m)
113113
114114 request = funD "request" $
@@ -122,7 +122,7 @@ requestDecl n p api url fs m =
122122 [ patBind noLoc (pvar "go") $
123123 appFun (var "clientWithRoute") $
124124 [ ExpTypeSig noLoc (var "Proxy") $
125− TyApp (tycon "Proxy") (TyCon (UnQual api))
125+ TyApp (TyCon "Proxy") (TyCon (UnQual api))
126126 , var "r"
127127 , var "u"
128128 ]
@@ -142,13 +142,13 @@ requestDecl n p api url fs m =
142142 prec = PRec (UnQual (dname n)) [PFieldWildcard]
143143
144144jsonDecls :: Global -> Prefix -> Map Local Solved -> [Decl]
145−jsonDecls n p (Map.toList -> rs) = [from, to]
145+jsonDecls g p (Map.toList -> rs) = [from, to]
146146 where
147− from = InstDecl noLoc Nothing [] [] (unqual "FromJSON") [tycon n]
147+ from = InstDecl noLoc Nothing [] [] (unqual "FromJSON") [tycon g]
148148 [ funD "parseJSON" $
149− app (app (var "withObject") (str (global n))) $
149+ app (app (var "withObject") (dstr g)) $
150150 lamE noLoc [pvar "o"] $
151− ctorE n (map decode rs)
151+ ctorE g (map decode rs)
152152 ]
153153
154154 decode (l, s)
@@ -157,8 +157,8 @@ jsonDecls n p (Map.toList -> rs) = [from, to]
157157 | monoid s = defJS l (var "mempty")
158158 | otherwise = optJS l
159159
160− to = InstDecl noLoc Nothing [] [] (unqual "ToJSON") [tycon n]
161− [ wildcardD "toJSON" n omit none (map encode rs)
160+ to = InstDecl noLoc Nothing [] [] (unqual "ToJSON") [tycon g]
161+ [ wildcardD "toJSON" g omit none (map encode rs)
162162 ]
163163
164164 omit = app (var "object")
@@ -171,7 +171,7 @@ jsonDecls n p (Map.toList -> rs) = [from, to]
171171 | TMaybe {} <- _type s = infixApp (paren (app n o)) "<$>" a
172172 | otherwise = app (var "Just") (infixApp n ".=" a)
173173 where
174− n = str (local l)
174+ n = fstr l
175175 a = var (fname p l)
176176 o = var ".="
177177
@@ -191,13 +191,13 @@ wildcardD f n enc x = \case
191191 prec = PRec (UnQual (dname n)) [PFieldWildcard]
192192
193193defJS :: Local -> Exp -> Exp
194−defJS n x = infixApp (infixApp (var "o") ".:?" (str (local n))) ".!=" x
194+defJS n x = infixApp (infixApp (var "o") ".:?" (fstr n)) ".!=" x
195195
196196reqJS :: Local -> Exp
197−reqJS = infixApp (var "o") ".:" . str . local
197+reqJS = infixApp (var "o") ".:" . fstr
198198
199199optJS :: Local -> Exp
200−optJS = infixApp (var "o") ".:?" . str . local
200+optJS = infixApp (var "o") ".:?" . fstr
201201
202202funD :: String -> Exp -> InstDecl
203203funD f = InsDecl . patBind noLoc (pvar (name f))
@@ -263,7 +263,7 @@ fieldUpdate p l s = FieldUpdate (UnQual (fname p l)) rhs
263263
264264lensSig :: Global -> Prefix -> Local -> Solved -> Decl
265265lensSig n p l s = TypeSig noLoc [lname p l] $
266− TyApp (TyApp (tycon "Lens'") (tycon n))
266+ TyApp (TyApp (TyCon "Lens'") (tycon n))
267267 (externalType (_type s))
268268
269269lensDecl :: Prefix -> Local -> Solved -> Decl
@@ -305,46 +305,46 @@ externalType :: TType -> Type
305305externalType = \case
306306 TType r -> tycon r
307307 TMaybe t@TList {} -> externalType t
308− TMaybe t -> TyApp (tycon "Maybe") (externalType t)
308+ TMaybe t -> TyApp (TyCon "Maybe") (externalType t)
309309 TList t -> TyList (externalType t)
310310 TLit l -> externalLit l
311311
312312internalType :: TType -> Type
313313internalType = \case
314314 TType r -> tycon r
315− TMaybe t -> TyApp (tycon "Maybe") (internalType t)
315+ TMaybe t -> TyApp (TyCon "Maybe") (internalType t)
316316 TList t -> TyList (internalType t)
317317 TLit l -> internalLit l
318318
319319externalLit :: Lit -> Type
320320externalLit = \case
321− Text -> tycon "Text"
322− Bool -> tycon "Bool"
323− Time -> tycon "UTCTime"
324− Date -> tycon "UTCTime"
325− Nat -> tycon "Natural"
326− Float -> tycon "Float"
327− Double -> tycon "Double"
328− Byte -> tycon "Word8"
329− UInt32 -> tycon "Word32"
330− UInt64 -> tycon "Word64"
331− Int32 -> tycon "Int32"
332− Int64 -> tycon "Int64"
321+ Text -> TyCon "Text"
322+ Bool -> TyCon "Bool"
323+ Time -> TyCon "UTCTime"
324+ Date -> TyCon "UTCTime"
325+ Nat -> TyCon "Natural"
326+ Float -> TyCon "Float"
327+ Double -> TyCon "Double"
328+ Byte -> TyCon "Word8"
329+ UInt32 -> TyCon "Word32"
330+ UInt64 -> TyCon "Word64"
331+ Int32 -> TyCon "Int32"
332+ Int64 -> TyCon "Int64"
333333
334334internalLit :: Lit -> Type
335335internalLit = \case
336− Text -> tycon "Text"
337− Bool -> tycon "Bool"
338− Time -> tycon "UTCTime"
339− Date -> tycon "UTCTime"
340− Nat -> tycon "Nat"
341− Float -> tycon "Float"
342− Double -> tycon "Double"
343− Byte -> tycon "Word8"
344− UInt32 -> tycon "Word32"
345− UInt64 -> tycon "Word64"
346− Int32 -> tycon "Int32"
347− Int64 -> tycon "Int64"
336+ Text -> TyCon "Text"
337+ Bool -> TyCon "Bool"
338+ Time -> TyCon "UTCTime"
339+ Date -> TyCon "UTCTime"
340+ Nat -> TyCon "Nat"
341+ Float -> TyCon "Float"
342+ Double -> TyCon "Double"
343+ Byte -> TyCon "Word8"
344+ UInt32 -> TyCon "Word32"
345+ UInt64 -> TyCon "Word64"
346+ Int32 -> TyCon "Int32"
347+ Int64 -> TyCon "Int64"
348348
349349mapping :: TType -> Exp -> Exp
350350mapping t e = infixE e "." (go t)
@@ -372,7 +372,7 @@ sing :: Text -> Type
372372sing = TyCon . unqual . Text.unpack . flip mappend "\"" . mappend "\""
373373
374374tycon :: Global -> Type
375−tycon = TyCon . unqual . Text.unpack . global
375+tycon = TyCon . UnQual . dname
376376
377377unqual :: String -> QName
378378unqual = UnQual . name