git.iko.soy/rowtype-yoga/purescript-docs-search
on master help sign in
Add KindedType
commit66bffd8d29299d4613f8fb2bd1ad6745ef015084 authorVladimir Kalnitsky <klntsky@gmail.com> dateSat 7 May 2022, 17:11 (4 years ago) parent6cc8a7f
6 files changed+36−9
src/Docs/Search/App/SearchResults.purs+3 src/Docs/Search/TypeDecoder.purs+5−3 src/Docs/Search/TypePrinter.purs+2 src/Docs/Search/TypeQuery.purs+11−6 src/Docs/Search/TypeShape.purs+2 test/Test/TypeJson.purs+13
src/Docs/Search/App/SearchResults.purs+3
@@ -561,6 +561,9 @@ renderType = case _ of
561561 ty@REmpty -> renderRow true ty
562562 ty@(RCons _ _ _) -> renderRow true ty
563563
564+ Kinded t1 t2 ->
565+ HH.span_ [ renderType t1, space, syntax "::", space, renderType t2 ]
566+
564567 BinaryNoParensType op t1 t2 ->
565568 HH.span_
566569 [ renderType t1
src/Docs/Search/TypeDecoder.purs+5−3
@@ -112,10 +112,8 @@ data Type
112112 | REmpty
113113 -- | A non-empty row
114114 | RCons Identifier Type Type
115− {-
116115 -- | A type with a kind annotation
117− | Kinded Type Kind
118− -}
116+ | Kinded Type Type
119117 -- | Binary operator application. During the rebracketing phase of desugaring,
120118 -- this data constructor will be removed.
121119 | BinaryNoParensType Type Type Type
@@ -168,6 +166,9 @@ instance decodeJsonType :: DecodeJson Type where
168166 "RCons" ->
169167 decodeContents (decodeTriple RCons (const err)) (Left err) json
170168 where err = mkJsonError' "RCons" json
169+ "KindedType" ->
170+ decodeContents (decodeTuple Kinded (const err)) (Left err) json
171+ where err = mkJsonError' "KindedType" json
171172 "BinaryNoParensType" ->
172173 decodeContents (decodeTriple BinaryNoParensType (const err)) (Left err) json
173174 where err = mkJsonError' "BinaryNoParens" json
@@ -191,6 +192,7 @@ instance encodeJsonType :: EncodeJson Type where
191192 ConstrainedType c t -> tagged "ConstrainedType" (encodeTuple c t)
192193 REmpty -> tagged "REmpty" jsonEmptyObject
193194 RCons s t1 t2 -> tagged "RCons" (encodeTriple s t1 t2)
195+ Kinded t1 t2 -> tagged "KindedType" (encodeTuple t1 t2)
194196 ParensInType t -> tagged "ParensInType" (encodeJson t)
195197 TypeWildcard -> tagged "TypeWildcard" jsonEmptyObject
196198 BinaryNoParensType t1 t2 t3 ->
src/Docs/Search/TypePrinter.purs+2
@@ -51,6 +51,8 @@ showType = case _ of
5151 ty@REmpty -> showRow true ty
5252 ty@(RCons _ _ _) -> showRow true ty
5353
54+ Kinded t1 t2 -> showType t1 <> " :: " <> showType t2
55+
5456 BinaryNoParensType op t1 t2 ->
5557 showType t1 <>
5658 space <>
src/Docs/Search/TypeQuery.purs+11−6
@@ -236,13 +236,13 @@ unify query type_ = go Nil (List.singleton { q: query, t: type_ })
236236 -- * Names
237237 go acc ({ q: QConst qname, t: TypeConstructor (QualifiedName { name }) } : rest) =
238238 go (Match qname name : acc) rest
239− go acc ({ q: QConst qname, t } : rest) =
239+ go acc ({ q: QConst _, t } : rest) =
240240 go (TypeMismatch t : acc) rest
241− go acc ({ q, t: TypeConstructor (QualifiedName { name }) } : rest) =
241+ go acc ({ q, t: TypeConstructor (QualifiedName _) } : rest) =
242242 go (QueryMismatch q : acc) rest
243243
244244 -- type operators can't appear in type queries: this is always a mismatch
245− go acc ({ q, t: TypeOp (QualifiedName { name }) } : rest) =
245+ go acc ({ q, t: TypeOp (QualifiedName _) } : rest) =
246246 go (QueryMismatch q : acc) rest
247247 go acc ({ q, t: t@(BinaryNoParensType _ _ _) } : rest) =
248248 go (Mismatch q t : acc) rest
@@ -253,7 +253,7 @@ unify query type_ = go Nil (List.singleton { q: query, t: type_ })
253253 (QualifiedName { moduleNameParts: [ "Prim" ]
254254 , name: Identifier "Function" })) t1) t2 } : rest) =
255255 go acc ({ q: q1, t: t1 } : { q: q2, t: t2 } : rest)
256− go acc ({ q: q@(QFun q1 q2), t } : rest) =
256+ go acc ({ q: q@(QFun _ _), t } : rest) =
257257 go (Mismatch q t : acc) rest
258258
259259 -- * Rows
@@ -261,7 +261,7 @@ unify query type_ = go Nil (List.singleton { q: query, t: type_ })
261261 , t: TypeApp (TypeConstructor
262262 (QualifiedName { moduleNameParts: [ "Prim" ]
263263 , name: Identifier "Record" })) row } : rest) =
264− let { rows, ty } = joinRows row
264+ let { rows } = joinRows row
265265 qRowsLength = List.length qRows
266266 rowsLength = List.length rows in
267267 if rowsLength == qRowsLength then
@@ -297,7 +297,10 @@ unify query type_ = go Nil (List.singleton { q: query, t: type_ })
297297 go acc ({ q, t: REmpty } : rest) =
298298 go (QueryMismatch q : acc) rest
299299
300− go acc ({ q, t: t@(KindApp _ _) } : rest) =
300+ go acc ({ q, t: Kinded _ _} : rest) =
301+ go (QueryMismatch q : acc) rest
302+
303+ go acc ({ t: t@(KindApp _ _) } : rest) =
301304 go (TypeMismatch t : acc) rest
302305
303306
@@ -429,6 +432,8 @@ typeSize = go 0 <<< List.singleton
429432 go (n + 1) (t1 : t2 : rest)
430433 go n (REmpty : rest) =
431434 go (n + 1) rest
435+ go n (Kinded t1 t2 : rest) =
436+ go n (t1 : t2 : rest)
432437 go n (BinaryNoParensType op t1 t2 : rest) =
433438 go (n + 1) (t1 : t2 : rest)
434439 go n (ParensInType t : rest) =
src/Docs/Search/TypeShape.purs+2
@@ -139,6 +139,8 @@ shapeOfType ty = List.reverse $ go (pure ty) Nil
139139 sorted = List.sortBy (\x y -> compare x.row y.row) joined.rows
140140 typesInRow = sorted <#> (_.ty)
141141
142+ Kinded t1 _t2 -> go (t1 : rest) acc
143+
142144 BinaryNoParensType op l r ->
143145 go (TypeApp (TypeApp op l) r : rest) acc
144146
test/Test/TypeJson.purs+13
@@ -268,6 +268,19 @@ tests = do
268268 """
269269 assertRight (decodeJson kindAppJson) $
270270 KindApp REmpty (TypeConstructor (qualified ["Prim"] "Type"))
271+ test "KindedType" do
272+ let kindedTypeJson = mkJson """
273+ {"annotation":[],"tag":"KindedType","contents":[{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Data","Const"],"Const"]},{"annotation":[],"tag":"TypeConstructor","contents":[["Data","Void"],"Void"]}]},{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeApp","contents":[{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Type"]}]},{"annotation":[],"tag":"TypeConstructor","contents":[["Prim"],"Type"]}]}]}
274+ """
275+ assertRight (decodeJson kindedTypeJson) $
276+ Kinded
277+ (TypeApp
278+ (TypeConstructor (qualified ["Data","Const"] "Const"))
279+ (TypeConstructor (qualified ["Data","Void"] "Void")))
280+ (TypeApp (TypeApp
281+ (TypeConstructor (qualified ["Prim"] "Function"))
282+ (TypeConstructor (qualified ["Prim"] "Type" )))
283+ (TypeConstructor (qualified ["Prim"] "Type")))
271284 suite "jsons" do
272285
273286 test "jsons #1" do