@@ -25,6 +25,7 @@ import Language.PureScript.AST
2525import Language.PureScript.Crash
2626import Language.PureScript.Errors
2727import Language.PureScript.Externs
28+import Language.PureScript.Kinds
2829import Language.PureScript.Linter.Imports
2930import Language.PureScript.Names
3031import Language.PureScript.Sugar.Names.Env
@@ -98,6 +99,9 @@ desugarImportsWithEnv externs modules = do
9899 exportedRefs :: Ord a => (DeclarationRef -> Maybe a) -> M.Map a ModuleName
99100 exportedRefs f = M.fromList $ (, efModuleName) <$> mapMaybe f efExports
100101
102+ exportedKinds :: M.Map (ProperName 'KindName) ModuleName
103+ exportedKinds = exportedRefs getKindRef
104+
101105 updateEnv :: ([Module], Env) -> Module -> m ([Module], Env)
102106 updateEnv (ms, env) m@(Module ss _ mn _ refs) = do
103107 members <- findExportable m
@@ -128,6 +132,7 @@ elaborateExports exps (Module ss coms mn decls refs) =
128132 ++ go TypeClassRef exportedTypeClasses
129133 ++ go ValueRef exportedValues
130134 ++ go ValueOpRef exportedValueOps
135+ ++ go KindRef exportedKinds
131136 ++ maybe [] (filter isModuleRef) refs
132137 where
133138
@@ -165,17 +170,24 @@ renameInModule imports (Module ss coms mn decls exps) =
165170 updateDecl (_, bound) d@(PositionedDeclaration pos _ _) =
166171 return ((Just pos, bound), d)
167172 updateDecl (pos, bound) (DataDeclaration dtype name args dctors) =
168− (,) (pos, bound) <$> (DataDeclaration dtype name args <$> traverse (sndM (traverse (updateTypesEverywhere pos))) dctors)
173+ (,) (pos, bound) <$> (DataDeclaration dtype name <$> updateTypeArguments pos args
174+ <*> traverse (sndM (traverse (updateTypesEverywhere pos))) dctors)
169175 updateDecl (pos, bound) (TypeSynonymDeclaration name ps ty) =
170− (,) (pos, bound) <$> (TypeSynonymDeclaration name ps <$> updateTypesEverywhere pos ty)
176+ (,) (pos, bound) <$> (TypeSynonymDeclaration name <$> updateTypeArguments pos ps
177+ <*> updateTypesEverywhere pos ty)
171178 updateDecl (pos, bound) (TypeClassDeclaration className args implies deps ds) =
172− (,) (pos, bound) <$> (TypeClassDeclaration className args <$> updateConstraints pos implies <*> pure deps <*> pure ds)
179+ (,) (pos, bound) <$> (TypeClassDeclaration className <$> updateTypeArguments pos args
180+ <*> updateConstraints pos implies
181+ <*> pure deps
182+ <*> pure ds)
173183 updateDecl (pos, bound) (TypeInstanceDeclaration name cs cn ts ds) =
174184 (,) (pos, bound) <$> (TypeInstanceDeclaration name <$> updateConstraints pos cs <*> updateClassName cn pos <*> traverse (updateTypesEverywhere pos) ts <*> pure ds)
175185 updateDecl (pos, bound) (TypeDeclaration name ty) =
176186 (,) (pos, bound) <$> (TypeDeclaration name <$> updateTypesEverywhere pos ty)
177187 updateDecl (pos, bound) (ExternDeclaration name ty) =
178188 (,) (pos, name : bound) <$> (ExternDeclaration name <$> updateTypesEverywhere pos ty)
189+ updateDecl (pos, bound) (ExternDataDeclaration name ki) =
190+ (,) (pos, bound) <$> (ExternDataDeclaration name <$> updateKindsEverywhere pos ki)
179191 updateDecl (pos, bound) (TypeFixityDeclaration fixity alias op) =
180192 (,) (pos, bound) <$> (TypeFixityDeclaration fixity <$> updateTypeName alias pos <*> pure op)
181193 updateDecl (pos, bound) (ValueFixityDeclaration fixity (Qualified mn' (Left alias)) op) =
@@ -238,6 +250,19 @@ renameInModule imports (Module ss coms mn decls exps) =
238250 letBoundVariable (PositionedDeclaration _ _ d) = letBoundVariable d
239251 letBoundVariable _ = Nothing
240252
253+ updateKindsEverywhere :: Maybe SourceSpan -> Kind -> m Kind
254+ updateKindsEverywhere pos = everywhereOnKindsM updateKind
255+ where
256+ updateKind :: Kind -> m Kind
257+ updateKind (NamedKind name) = NamedKind <$> updateKindName name pos
258+ updateKind k = return k
259+
260+ updateTypeArguments
261+ :: (Traversable f, Traversable g)
262+ => Maybe SourceSpan
263+ -> f (a, g Kind) -> m (f (a, g Kind))
264+ updateTypeArguments pos = traverse (sndM (traverse (updateKindsEverywhere pos)))
265+
241266 updateTypesEverywhere :: Maybe SourceSpan -> Type -> m Type
242267 updateTypesEverywhere pos = everywhereOnTypesM updateType
243268 where
@@ -245,16 +270,17 @@ renameInModule imports (Module ss coms mn decls exps) =
245270 updateType (TypeOp name) = TypeOp <$> updateTypeOpName name pos
246271 updateType (TypeConstructor name) = TypeConstructor <$> updateTypeName name pos
247272 updateType (ConstrainedType cs t) = ConstrainedType <$> traverse updateInConstraint cs <*> pure t
273+ updateType (KindedType t k) = KindedType t <$> updateKindsEverywhere pos k
248274 updateType t = return t
249275 updateInConstraint :: Constraint -> m Constraint
250276 updateInConstraint (Constraint name ts info) =
251277 Constraint <$> updateClassName name pos <*> pure ts <*> pure info
252278
253279 updateConstraints :: Maybe SourceSpan -> [Constraint] -> m [Constraint]
254− updateConstraints pos = traverse $ \(Constraint name ts info) ->
255− Constraint
256− <$> updateClassName name pos
257− <*> traverse (updateTypesEverywhere pos) ts
280+ updateConstraints pos = traverse $ \(Constraint name ts info) ->
281+ Constraint
282+ <$> updateClassName name pos
283+ <*> traverse (updateTypesEverywhere pos) ts
258284 <*> pure info
259285
260286 updateTypeName
@@ -290,6 +316,12 @@ renameInModule imports (Module ss coms mn decls exps) =
290316 -> m (Qualified (OpName 'ValueOpName))
291317 updateValueOpName = update (importedValueOps imports) ValOpName
292318
319+ updateKindName
320+ :: Qualified (ProperName 'KindName)
321+ -> Maybe SourceSpan
322+ -> m (Qualified (ProperName 'KindName))
323+ updateKindName = update (importedKinds imports) KiName
324+
293325 -- Update names so unqualified references become qualified, and locally
294326 -- qualified references are replaced with their canoncial qualified names
295327 -- (e.g. M.Map -> Data.Map.Map).