@@ -26,6 +26,7 @@ import Control.Applicative
2626import Control.Monad ((<=<))
2727
2828import Language.PureScript.Names
29+import Language.PureScript.Kinds
2930import Language.PureScript.Traversals
3031
3132-- |
@@ -78,6 +79,11 @@ data Type
7879 --
7980 | RCons String Type Type
8081 -- |
82+ -- A type with a kind annotation
83+ --
84+ | KindedType Type Kind
85+ --
86+ -- |
8187 -- A placeholder used in pretty printing
8288 --
8389 | PrettyPrintFunction Type Type
@@ -142,6 +148,7 @@ replaceTypeVars = replaceTypeVars' []
142148 | otherwise = ForAll v (go (v : bs) t) sco
143149 go bs (ConstrainedType cs t) = ConstrainedType (map (second $ map (go bs)) cs) (go bs t)
144150 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
145152 go _ ty = ty
146153 genName orig inUse = try 0
147154 where
@@ -177,6 +184,7 @@ freeTypeVariables = nub . go []
177184 go bound (ForAll v t _) = go (v : bound) t
178185 go bound (ConstrainedType cs t) = concatMap (concatMap (go bound) . snd) cs ++ go bound t
179186 go bound (RCons _ t r) = go bound t ++ go bound r
187+ go bound (KindedType t _) = go bound t
180188 go _ _ = []
181189
182190-- |
@@ -213,6 +221,7 @@ everywhereOnTypes f = go
213221 go (ForAll arg ty sco) = f (ForAll arg (go ty) sco)
214222 go (ConstrainedType cs ty) = f (ConstrainedType (map (fmap (map go)) cs) (go ty))
215223 go (RCons name ty rest) = f (RCons name (go ty) (go rest))
224+ go (KindedType ty k) = f (KindedType (go ty) k)
216225 go (PrettyPrintFunction t1 t2) = f (PrettyPrintFunction (go t1) (go t2))
217226 go (PrettyPrintArray t) = f (PrettyPrintArray (go t))
218227 go (PrettyPrintObject t) = f (PrettyPrintObject (go t))
@@ -227,6 +236,7 @@ everywhereOnTypesTopDown f = go . f
227236 go (ForAll arg ty sco) = ForAll arg (go (f ty)) sco
228237 go (ConstrainedType cs ty) = ConstrainedType (map (fmap (map (go . f))) cs) (go (f ty))
229238 go (RCons name ty rest) = RCons name (go (f ty)) (go (f rest))
239+ go (KindedType ty k) = KindedType (go (f ty)) k
230240 go (PrettyPrintFunction t1 t2) = PrettyPrintFunction (go (f t1)) (go (f t2))
231241 go (PrettyPrintArray t) = PrettyPrintArray (go (f t))
232242 go (PrettyPrintObject t) = PrettyPrintObject (go (f t))
@@ -241,6 +251,7 @@ everywhereOnTypesM f = go
241251 go (ForAll arg ty sco) = (ForAll arg <$> go ty <*> pure sco) >>= f
242252 go (ConstrainedType cs ty) = (ConstrainedType <$> mapM (sndM (mapM go)) cs <*> go ty) >>= f
243253 go (RCons name ty rest) = (RCons name <$> go ty <*> go rest) >>= f
254+ go (KindedType ty k) = (KindedType <$> go ty <*> pure k) >>= f
244255 go (PrettyPrintFunction t1 t2) = (PrettyPrintFunction <$> go t1 <*> go t2) >>= f
245256 go (PrettyPrintArray t) = (PrettyPrintArray <$> go t) >>= f
246257 go (PrettyPrintObject t) = (PrettyPrintObject <$> go t) >>= f
@@ -255,6 +266,7 @@ everywhereOnTypesTopDownM f = go <=< f
255266 go (ForAll arg ty sco) = ForAll arg <$> (f ty >>= go) <*> pure sco
256267 go (ConstrainedType cs ty) = ConstrainedType <$> mapM (sndM (mapM (go <=< f))) cs <*> (f ty >>= go)
257268 go (RCons name ty rest) = RCons name <$> (f ty >>= go) <*> (f rest >>= go)
269+ go (KindedType ty k) = KindedType <$> (f ty >>= go) <*> pure k
258270 go (PrettyPrintFunction t1 t2) = PrettyPrintFunction <$> (f t1 >>= go) <*> (f t2 >>= go)
259271 go (PrettyPrintArray t) = PrettyPrintArray <$> (f t >>= go)
260272 go (PrettyPrintObject t) = PrettyPrintObject <$> (f t >>= go)
@@ -269,6 +281,7 @@ everythingOnTypes (<>) f = go
269281 go t@(ForAll _ ty _) = f t <> go ty
270282 go t@(ConstrainedType cs ty) = foldl (<>) (f t) (map go $ concatMap snd cs) <> go ty
271283 go t@(RCons _ ty rest) = f t <> go ty <> go rest
284+ go t@(KindedType ty _) = f t <> go ty
272285 go t@(PrettyPrintFunction t1 t2) = f t <> go t1 <> go t2
273286 go t@(PrettyPrintArray t1) = f t <> go t1
274287 go t@(PrettyPrintObject t1) = f t <> go t1