@@ -26,6 +26,7 @@ import Control.Applicative
26import Control.Monad ((<=<))
26import Control.Monad ((<=<))
28import Language.PureScript.Names
28import Language.PureScript.Names
29+import Language.PureScript.Kinds
29import Language.PureScript.Traversals
30import Language.PureScript.Traversals
@@ -78,6 +79,11 @@ data Type
79 | RCons String Type Type
80 | RCons String Type Type
82+ -- A type with a kind annotation
84+ | KindedType Type Kind
81 -- A placeholder used in pretty printing
87 -- A placeholder used in pretty printing
83 | PrettyPrintFunction Type Type
89 | PrettyPrintFunction Type Type
@@ -142,6 +148,7 @@ replaceTypeVars = replaceTypeVars' []
142 | otherwise = ForAll v (go (v : bs) t) sco
148 | otherwise = ForAll v (go (v : bs) t) sco
143 go bs (ConstrainedType cs t) = ConstrainedType (map (second $ map (go bs)) cs) (go bs t)
149 go bs (ConstrainedType cs t) = ConstrainedType (map (second $ map (go bs)) cs) (go bs t)
144 go bs (RCons name' t r) = RCons name' (go bs t) (go bs r)
150 go bs (RCons name' t r) = RCons name' (go bs t) (go bs r)
151+ go bs (KindedType t k) = KindedType (go bs t) k
145 go _ ty = ty
152 go _ ty = ty
146 genName orig inUse = try 0
153 genName orig inUse = try 0
@@ -177,6 +184,7 @@ freeTypeVariables = nub . go []
177 go bound (ForAll v t _) = go (v : bound) t
184 go bound (ForAll v t _) = go (v : bound) t
178 go bound (ConstrainedType cs t) = concatMap (concatMap (go bound) . snd) cs ++ go bound t
185 go bound (ConstrainedType cs t) = concatMap (concatMap (go bound) . snd) cs ++ go bound t
179 go bound (RCons _ t r) = go bound t ++ go bound r
186 go bound (RCons _ t r) = go bound t ++ go bound r
187+ go bound (KindedType t _) = go bound t
180 go _ _ = []
188 go _ _ = []
@@ -213,6 +221,7 @@ everywhereOnTypes f = go
213 go (ForAll arg ty sco) = f (ForAll arg (go ty) sco)
221 go (ForAll arg ty sco) = f (ForAll arg (go ty) sco)
214 go (ConstrainedType cs ty) = f (ConstrainedType (map (fmap (map go)) cs) (go ty))
222 go (ConstrainedType cs ty) = f (ConstrainedType (map (fmap (map go)) cs) (go ty))
215 go (RCons name ty rest) = f (RCons name (go ty) (go rest))
223 go (RCons name ty rest) = f (RCons name (go ty) (go rest))
224+ go (KindedType ty k) = f (KindedType (go ty) k)
216 go (PrettyPrintFunction t1 t2) = f (PrettyPrintFunction (go t1) (go t2))
225 go (PrettyPrintFunction t1 t2) = f (PrettyPrintFunction (go t1) (go t2))
217 go (PrettyPrintArray t) = f (PrettyPrintArray (go t))
226 go (PrettyPrintArray t) = f (PrettyPrintArray (go t))
218 go (PrettyPrintObject t) = f (PrettyPrintObject (go t))
227 go (PrettyPrintObject t) = f (PrettyPrintObject (go t))
@@ -227,6 +236,7 @@ everywhereOnTypesTopDown f = go . f
227 go (ForAll arg ty sco) = ForAll arg (go (f ty)) sco
236 go (ForAll arg ty sco) = ForAll arg (go (f ty)) sco
228 go (ConstrainedType cs ty) = ConstrainedType (map (fmap (map (go . f))) cs) (go (f ty))
237 go (ConstrainedType cs ty) = ConstrainedType (map (fmap (map (go . f))) cs) (go (f ty))
229 go (RCons name ty rest) = RCons name (go (f ty)) (go (f rest))
238 go (RCons name ty rest) = RCons name (go (f ty)) (go (f rest))
239+ go (KindedType ty k) = KindedType (go (f ty)) k
230 go (PrettyPrintFunction t1 t2) = PrettyPrintFunction (go (f t1)) (go (f t2))
240 go (PrettyPrintFunction t1 t2) = PrettyPrintFunction (go (f t1)) (go (f t2))
231 go (PrettyPrintArray t) = PrettyPrintArray (go (f t))
241 go (PrettyPrintArray t) = PrettyPrintArray (go (f t))
232 go (PrettyPrintObject t) = PrettyPrintObject (go (f t))
242 go (PrettyPrintObject t) = PrettyPrintObject (go (f t))
@@ -241,6 +251,7 @@ everywhereOnTypesM f = go
241 go (ForAll arg ty sco) = (ForAll arg <$> go ty <*> pure sco) >>= f
251 go (ForAll arg ty sco) = (ForAll arg <$> go ty <*> pure sco) >>= f
242 go (ConstrainedType cs ty) = (ConstrainedType <$> mapM (sndM (mapM go)) cs <*> go ty) >>= f
252 go (ConstrainedType cs ty) = (ConstrainedType <$> mapM (sndM (mapM go)) cs <*> go ty) >>= f
243 go (RCons name ty rest) = (RCons name <$> go ty <*> go rest) >>= f
253 go (RCons name ty rest) = (RCons name <$> go ty <*> go rest) >>= f
254+ go (KindedType ty k) = (KindedType <$> go ty <*> pure k) >>= f
244 go (PrettyPrintFunction t1 t2) = (PrettyPrintFunction <$> go t1 <*> go t2) >>= f
255 go (PrettyPrintFunction t1 t2) = (PrettyPrintFunction <$> go t1 <*> go t2) >>= f
245 go (PrettyPrintArray t) = (PrettyPrintArray <$> go t) >>= f
256 go (PrettyPrintArray t) = (PrettyPrintArray <$> go t) >>= f
246 go (PrettyPrintObject t) = (PrettyPrintObject <$> go t) >>= f
257 go (PrettyPrintObject t) = (PrettyPrintObject <$> go t) >>= f
@@ -255,6 +266,7 @@ everywhereOnTypesTopDownM f = go <=< f
255 go (ForAll arg ty sco) = ForAll arg <$> (f ty >>= go) <*> pure sco
266 go (ForAll arg ty sco) = ForAll arg <$> (f ty >>= go) <*> pure sco
256 go (ConstrainedType cs ty) = ConstrainedType <$> mapM (sndM (mapM (go <=< f))) cs <*> (f ty >>= go)
267 go (ConstrainedType cs ty) = ConstrainedType <$> mapM (sndM (mapM (go <=< f))) cs <*> (f ty >>= go)
257 go (RCons name ty rest) = RCons name <$> (f ty >>= go) <*> (f rest >>= go)
268 go (RCons name ty rest) = RCons name <$> (f ty >>= go) <*> (f rest >>= go)
269+ go (KindedType ty k) = KindedType <$> (f ty >>= go) <*> pure k
258 go (PrettyPrintFunction t1 t2) = PrettyPrintFunction <$> (f t1 >>= go) <*> (f t2 >>= go)
270 go (PrettyPrintFunction t1 t2) = PrettyPrintFunction <$> (f t1 >>= go) <*> (f t2 >>= go)
259 go (PrettyPrintArray t) = PrettyPrintArray <$> (f t >>= go)
271 go (PrettyPrintArray t) = PrettyPrintArray <$> (f t >>= go)
260 go (PrettyPrintObject t) = PrettyPrintObject <$> (f t >>= go)
272 go (PrettyPrintObject t) = PrettyPrintObject <$> (f t >>= go)
@@ -269,6 +281,7 @@ everythingOnTypes (<>) f = go
269 go t@(ForAll _ ty _) = f t <> go ty
281 go t@(ForAll _ ty _) = f t <> go ty
270 go t@(ConstrainedType cs ty) = foldl (<>) (f t) (map go $ concatMap snd cs) <> go ty
282 go t@(ConstrainedType cs ty) = foldl (<>) (f t) (map go $ concatMap snd cs) <> go ty
271 go t@(RCons _ ty rest) = f t <> go ty <> go rest
283 go t@(RCons _ ty rest) = f t <> go ty <> go rest
284+ go t@(KindedType ty _) = f t <> go ty
272 go t@(PrettyPrintFunction t1 t2) = f t <> go t1 <> go t2
285 go t@(PrettyPrintFunction t1 t2) = f t <> go t1 <> go t2
273 go t@(PrettyPrintArray t1) = f t <> go t1
286 go t@(PrettyPrintArray t1) = f t <> go t1
274 go t@(PrettyPrintObject t1) = f t <> go t1
287 go t@(PrettyPrintObject t1) = f t <> go t1