@@ -32,7 +32,7 @@ import Language.Haskell.Exts.SrcLoc
32import Language.Haskell.Exts.Syntax hiding (Int, Lit)
32import Language.Haskell.Exts.Syntax hiding (Int, Lit)
34urlSig :: Name -> Decl
34urlSig :: Name -> Decl
35−urlSig n = TypeSig noLoc [n] (tycon "BaseUrl")
35+urlSig n = TypeSig noLoc [n] (TyCon "BaseUrl")
37urlDecl :: Name -> String -> Text -> Integer -> Decl
37urlDecl :: Name -> String -> Text -> Integer -> Decl
38urlDecl n s u p = sfun noLoc n [] (UnGuardedRhs rhs) noBinds
38urlDecl 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
40 rhs = appFun (var "BaseUrl") [var (name s), str u, intE p]
40 rhs = appFun (var "BaseUrl") [var (name s), str u, intE p]
42 -- type API = :<|> ...
42 -- type API = :<|> ...
43−apiAlias :: Name -> [Global] -> Decl
43+apiAlias :: Name -> [Name] -> Decl
44apiAlias n ls = TypeDecl noLoc n [] alias
44apiAlias n ls = TypeDecl noLoc n [] alias
46− alias = case map tycon ls of
46+ alias = case map (TyCon . UnQual) ls of
47 [] -> unit_tycon
47 [] -> unit_tycon
48 x:xs -> foldl' (\l r -> TyInfix l (UnQual (sym ":<|>")) r) x xs
48 x:xs -> foldl' (\l r -> TyInfix l (UnQual (sym ":<|>")) r) x xs
@@ -67,7 +67,7 @@ verbAlias n m = TypeDecl noLoc n [] alias
67 , c == '{'
67 , c == '{'
68 , Just k <- Map.lookup (toKey (Text.init t)) params
68 , Just k <- Map.lookup (toKey (Text.init t)) params
69 , _pLocation k == Path
69 , _pLocation k == Path
70− = TyApp (TyApp (tycon "Capture")
70+ = TyApp (TyApp (TyCon "Capture")
71 (sing (Text.init t)))
71 (sing (Text.init t)))
72 (terminalType (_type (_pParam k)))
72 (terminalType (_type (_pParam k)))
73 | otherwise = sing x
73 | otherwise = sing x
@@ -81,8 +81,8 @@ verbAlias n m = TypeDecl noLoc n [] alias
81 n = sing (local k)
81 n = sing (local k)
82 in case _pLocation x of
82 in case _pLocation x of
83 Query | x ^. iRepeated
83 Query | x ^. iRepeated
84− -> Just $ TyApp (TyApp (tycon "QueryParams") n) t
84+ -> Just $ TyApp (TyApp (TyCon "QueryParams") n) t
85− Query -> Just $ TyApp (TyApp (tycon "QueryParam") n) t
85+ Query -> Just $ TyApp (TyApp (TyCon "QueryParam") n) t
86 Path -> Nothing
86 Path -> Nothing
88 params = _mParameters m
88 params = _mParameters m
@@ -91,8 +91,8 @@ verbAlias n m = TypeDecl noLoc n [] alias
91 verb = TyApp (TyApp meth typ) res
91 verb = TyApp (TyApp meth typ) res
93 meth = TyCon . unqual . Text.unpack $ Text.toTitle (_mHttpMethod m)
93 meth = TyCon . unqual . Text.unpack $ Text.toTitle (_mHttpMethod m)
94− typ = tycon "'[JSON]"
94+ typ = TyCon "'[JSON]"
95− res = maybe (tycon "()") (tycon . ref) (_mResponse m)
95+ res = maybe (TyCon "()") (tycon . ref) (_mResponse m)
97requestDecl :: Global
97requestDecl :: Global
@@ -108,7 +108,7 @@ requestDecl n p api url fs m =
108 , requestWithRoute
108 , requestWithRoute
111− response = InsType noLoc (TyApp (tycon "Rs") (tycon n)) $
111+ response = InsType noLoc (TyApp (TyCon "Rs") (tycon n)) $
112 maybe unit_tycon (tycon . ref) (_mResponse m)
112 maybe unit_tycon (tycon . ref) (_mResponse m)
114 request = funD "request" $
114 request = funD "request" $
@@ -122,7 +122,7 @@ requestDecl n p api url fs m =
122 [ patBind noLoc (pvar "go") $
122 [ patBind noLoc (pvar "go") $
123 appFun (var "clientWithRoute") $
123 appFun (var "clientWithRoute") $
124 [ ExpTypeSig noLoc (var "Proxy") $
124 [ ExpTypeSig noLoc (var "Proxy") $
125− TyApp (tycon "Proxy") (TyCon (UnQual api))
125+ TyApp (TyCon "Proxy") (TyCon (UnQual api))
126 , var "r"
126 , var "r"
127 , var "u"
127 , var "u"
@@ -142,13 +142,13 @@ requestDecl n p api url fs m =
142 prec = PRec (UnQual (dname n)) [PFieldWildcard]
142 prec = PRec (UnQual (dname n)) [PFieldWildcard]
144jsonDecls :: Global -> Prefix -> Map Local Solved -> [Decl]
144jsonDecls :: Global -> Prefix -> Map Local Solved -> [Decl]
145−jsonDecls n p (Map.toList -> rs) = [from, to]
145+jsonDecls g p (Map.toList -> rs) = [from, to]
147− from = InstDecl noLoc Nothing [] [] (unqual "FromJSON") [tycon n]
147+ from = InstDecl noLoc Nothing [] [] (unqual "FromJSON") [tycon g]
148 [ funD "parseJSON" $
148 [ funD "parseJSON" $
149− app (app (var "withObject") (str (global n))) $
149+ app (app (var "withObject") (dstr g)) $
150 lamE noLoc [pvar "o"] $
150 lamE noLoc [pvar "o"] $
151− ctorE n (map decode rs)
151+ ctorE g (map decode rs)
154 decode (l, s)
154 decode (l, s)
@@ -157,8 +157,8 @@ jsonDecls n p (Map.toList -> rs) = [from, to]
157 | monoid s = defJS l (var "mempty")
157 | monoid s = defJS l (var "mempty")
158 | otherwise = optJS l
158 | otherwise = optJS l
160− to = InstDecl noLoc Nothing [] [] (unqual "ToJSON") [tycon n]
160+ to = InstDecl noLoc Nothing [] [] (unqual "ToJSON") [tycon g]
161− [ wildcardD "toJSON" n omit none (map encode rs)
161+ [ wildcardD "toJSON" g omit none (map encode rs)
164 omit = app (var "object")
164 omit = app (var "object")
@@ -171,7 +171,7 @@ jsonDecls n p (Map.toList -> rs) = [from, to]
171 | TMaybe {} <- _type s = infixApp (paren (app n o)) "<$>" a
171 | TMaybe {} <- _type s = infixApp (paren (app n o)) "<$>" a
172 | otherwise = app (var "Just") (infixApp n ".=" a)
172 | otherwise = app (var "Just") (infixApp n ".=" a)
174− n = str (local l)
174+ n = fstr l
175 a = var (fname p l)
175 a = var (fname p l)
176 o = var ".="
176 o = var ".="
@@ -191,13 +191,13 @@ wildcardD f n enc x = \case
191 prec = PRec (UnQual (dname n)) [PFieldWildcard]
191 prec = PRec (UnQual (dname n)) [PFieldWildcard]
193defJS :: Local -> Exp -> Exp
193defJS :: 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
196reqJS :: Local -> Exp
196reqJS :: Local -> Exp
197−reqJS = infixApp (var "o") ".:" . str . local
197+reqJS = infixApp (var "o") ".:" . fstr
199optJS :: Local -> Exp
199optJS :: Local -> Exp
200−optJS = infixApp (var "o") ".:?" . str . local
200+optJS = infixApp (var "o") ".:?" . fstr
202funD :: String -> Exp -> InstDecl
202funD :: String -> Exp -> InstDecl
203funD f = InsDecl . patBind noLoc (pvar (name f))
203funD f = InsDecl . patBind noLoc (pvar (name f))
@@ -263,7 +263,7 @@ fieldUpdate p l s = FieldUpdate (UnQual (fname p l)) rhs
264lensSig :: Global -> Prefix -> Local -> Solved -> Decl
264lensSig :: Global -> Prefix -> Local -> Solved -> Decl
265lensSig n p l s = TypeSig noLoc [lname p l] $
265lensSig n p l s = TypeSig noLoc [lname p l] $
266− TyApp (TyApp (tycon "Lens'") (tycon n))
266+ TyApp (TyApp (TyCon "Lens'") (tycon n))
267 (externalType (_type s))
267 (externalType (_type s))
269lensDecl :: Prefix -> Local -> Solved -> Decl
269lensDecl :: Prefix -> Local -> Solved -> Decl
@@ -305,46 +305,46 @@ externalType :: TType -> Type
305externalType = \case
305externalType = \case
306 TType r -> tycon r
306 TType r -> tycon r
307 TMaybe t@TList {} -> externalType t
307 TMaybe t@TList {} -> externalType t
308− TMaybe t -> TyApp (tycon "Maybe") (externalType t)
308+ TMaybe t -> TyApp (TyCon "Maybe") (externalType t)
309 TList t -> TyList (externalType t)
309 TList t -> TyList (externalType t)
310 TLit l -> externalLit l
310 TLit l -> externalLit l
312internalType :: TType -> Type
312internalType :: TType -> Type
313internalType = \case
313internalType = \case
314 TType r -> tycon r
314 TType r -> tycon r
315− TMaybe t -> TyApp (tycon "Maybe") (internalType t)
315+ TMaybe t -> TyApp (TyCon "Maybe") (internalType t)
316 TList t -> TyList (internalType t)
316 TList t -> TyList (internalType t)
317 TLit l -> internalLit l
317 TLit l -> internalLit l
319externalLit :: Lit -> Type
319externalLit :: Lit -> Type
320externalLit = \case
320externalLit = \case
321− Text -> tycon "Text"
321+ Text -> TyCon "Text"
322− Bool -> tycon "Bool"
322+ Bool -> TyCon "Bool"
323− Time -> tycon "UTCTime"
323+ Time -> TyCon "UTCTime"
324− Date -> tycon "UTCTime"
324+ Date -> TyCon "UTCTime"
325− Nat -> tycon "Natural"
325+ Nat -> TyCon "Natural"
326− Float -> tycon "Float"
326+ Float -> TyCon "Float"
327− Double -> tycon "Double"
327+ Double -> TyCon "Double"
328− Byte -> tycon "Word8"
328+ Byte -> TyCon "Word8"
329− UInt32 -> tycon "Word32"
329+ UInt32 -> TyCon "Word32"
330− UInt64 -> tycon "Word64"
330+ UInt64 -> TyCon "Word64"
331− Int32 -> tycon "Int32"
331+ Int32 -> TyCon "Int32"
332− Int64 -> tycon "Int64"
332+ Int64 -> TyCon "Int64"
334internalLit :: Lit -> Type
334internalLit :: Lit -> Type
335internalLit = \case
335internalLit = \case
336− Text -> tycon "Text"
336+ Text -> TyCon "Text"
337− Bool -> tycon "Bool"
337+ Bool -> TyCon "Bool"
338− Time -> tycon "UTCTime"
338+ Time -> TyCon "UTCTime"
339− Date -> tycon "UTCTime"
339+ Date -> TyCon "UTCTime"
340− Nat -> tycon "Nat"
340+ Nat -> TyCon "Nat"
341− Float -> tycon "Float"
341+ Float -> TyCon "Float"
342− Double -> tycon "Double"
342+ Double -> TyCon "Double"
343− Byte -> tycon "Word8"
343+ Byte -> TyCon "Word8"
344− UInt32 -> tycon "Word32"
344+ UInt32 -> TyCon "Word32"
345− UInt64 -> tycon "Word64"
345+ UInt64 -> TyCon "Word64"
346− Int32 -> tycon "Int32"
346+ Int32 -> TyCon "Int32"
347− Int64 -> tycon "Int64"
347+ Int64 -> TyCon "Int64"
349mapping :: TType -> Exp -> Exp
349mapping :: TType -> Exp -> Exp
350mapping t e = infixE e "." (go t)
350mapping t e = infixE e "." (go t)
@@ -372,7 +372,7 @@ sing :: Text -> Type
372sing = TyCon . unqual . Text.unpack . flip mappend "\"" . mappend "\""
372sing = TyCon . unqual . Text.unpack . flip mappend "\"" . mappend "\""
374tycon :: Global -> Type
374tycon :: Global -> Type
375−tycon = TyCon . unqual . Text.unpack . global
375+tycon = TyCon . UnQual . dname
377unqual :: String -> QName
377unqual :: String -> QName
378unqual = UnQual . name
378unqual = UnQual . name