@@ -39,21 +39,21 @@ import Language.PureScript.TypeClassDictionaries
39import Language.PureScript.Environment
39import Language.PureScript.Environment
40import Language.PureScript.Errors
40import Language.PureScript.Errors
42−addDataType :: ModuleName -> ProperName -> [String] -> [(ProperName, [Type])] -> Kind -> Check ()
42+addDataType :: ModuleName -> DataDeclType -> ProperName -> [String] -> [(ProperName, [Type])] -> Kind -> Check ()
43−addDataType moduleName name args dctors ctorKind = do
43+addDataType moduleName dtype name args dctors ctorKind = do
44 env <- getEnv
44 env <- getEnv
45 putEnv $ env { types = M.insert (Qualified (Just moduleName) name) (ctorKind, DataType args dctors) (types env) }
45 putEnv $ env { types = M.insert (Qualified (Just moduleName) name) (ctorKind, DataType args dctors) (types env) }
46 forM_ dctors $ \(dctor, tys) ->
46 forM_ dctors $ \(dctor, tys) ->
47 rethrow (strMsg ("Error in data constructor " ++ show dctor) <>) $
47 rethrow (strMsg ("Error in data constructor " ++ show dctor) <>) $
48− addDataConstructor moduleName name args dctor tys
48+ addDataConstructor moduleName dtype name args dctor tys
50−addDataConstructor :: ModuleName -> ProperName -> [String] -> ProperName -> [Type] -> Check ()
50+addDataConstructor :: ModuleName -> DataDeclType -> ProperName -> [String] -> ProperName -> [Type] -> Check ()
51−addDataConstructor moduleName name args dctor tys = do
51+addDataConstructor moduleName dtype name args dctor tys = do
52 env <- getEnv
52 env <- getEnv
53 let retTy = foldl TypeApp (TypeConstructor (Qualified (Just moduleName) name)) (map TypeVar args)
53 let retTy = foldl TypeApp (TypeConstructor (Qualified (Just moduleName) name)) (map TypeVar args)
54 let dctorTy = foldr function retTy tys
54 let dctorTy = foldr function retTy tys
55 let polyType = mkForAll args dctorTy
55 let polyType = mkForAll args dctorTy
56− putEnv $ env { dataConstructors = M.insert (Qualified (Just moduleName) dctor) (name, polyType) (dataConstructors env) }
56+ putEnv $ env { dataConstructors = M.insert (Qualified (Just moduleName) dctor) (dtype, name, polyType) (dataConstructors env) }
58addTypeSynonym :: ModuleName -> ProperName -> [String] -> Type -> Kind -> Check ()
58addTypeSynonym :: ModuleName -> ProperName -> [String] -> Type -> Kind -> Check ()
59addTypeSynonym moduleName name args ty kind = do
59addTypeSynonym moduleName name args ty kind = do
@@ -111,19 +111,19 @@ checkTypeClassInstance _ ty = throwError $ mkErrorStack "Type class instance hea
112typeCheckAll :: Maybe ModuleName -> ModuleName -> [Declaration] -> Check [Declaration]
112typeCheckAll :: Maybe ModuleName -> ModuleName -> [Declaration] -> Check [Declaration]
113typeCheckAll _ _ [] = return []
113typeCheckAll _ _ [] = return []
114−typeCheckAll mainModuleName moduleName (d@(DataDeclaration _ name args dctors) : rest) = do
114+typeCheckAll mainModuleName moduleName (d@(DataDeclaration dtype name args dctors) : rest) = do
115 rethrow (strMsg ("Error in type constructor " ++ show name) <>) $ do
115 rethrow (strMsg ("Error in type constructor " ++ show name) <>) $ do
116 ctorKind <- kindsOf True moduleName name args (concatMap snd dctors)
116 ctorKind <- kindsOf True moduleName name args (concatMap snd dctors)
117− addDataType moduleName name args dctors ctorKind
117+ addDataType moduleName dtype name args dctors ctorKind
118 ds <- typeCheckAll mainModuleName moduleName rest
118 ds <- typeCheckAll mainModuleName moduleName rest
119 return $ d : ds
119 return $ d : ds
120typeCheckAll mainModuleName moduleName (d@(DataBindingGroupDeclaration tys) : rest) = do
120typeCheckAll mainModuleName moduleName (d@(DataBindingGroupDeclaration tys) : rest) = do
121 rethrow (strMsg "Error in data binding group" <>) $ do
121 rethrow (strMsg "Error in data binding group" <>) $ do
122 let syns = mapMaybe toTypeSynonym tys
122 let syns = mapMaybe toTypeSynonym tys
123 let dataDecls = mapMaybe toDataDecl tys
123 let dataDecls = mapMaybe toDataDecl tys
124− (syn_ks, data_ks) <- kindsOfAll moduleName syns (map (\(name, args, dctors) -> (name, args, concatMap snd dctors)) dataDecls)
124+ (syn_ks, data_ks) <- kindsOfAll moduleName syns (map (\(_, name, args, dctors) -> (name, args, concatMap snd dctors)) dataDecls)
125− forM_ (zip dataDecls data_ks) $ \((name, args, dctors), ctorKind) ->
125+ forM_ (zip dataDecls data_ks) $ \((dtype, name, args, dctors), ctorKind) ->
126− addDataType moduleName name args dctors ctorKind
126+ addDataType moduleName dtype name args dctors ctorKind
127 forM_ (zip syns syn_ks) $ \((name, args, ty), kind) ->
127 forM_ (zip syns syn_ks) $ \((name, args, ty), kind) ->
128 addTypeSynonym moduleName name args ty kind
128 addTypeSynonym moduleName name args ty kind
129 ds <- typeCheckAll mainModuleName moduleName rest
129 ds <- typeCheckAll mainModuleName moduleName rest
@@ -132,7 +132,7 @@ typeCheckAll mainModuleName moduleName (d@(DataBindingGroupDeclaration tys) : re
132 toTypeSynonym (TypeSynonymDeclaration nm args ty) = Just (nm, args, ty)
132 toTypeSynonym (TypeSynonymDeclaration nm args ty) = Just (nm, args, ty)
133 toTypeSynonym (PositionedDeclaration _ d') = toTypeSynonym d'
133 toTypeSynonym (PositionedDeclaration _ d') = toTypeSynonym d'
134 toTypeSynonym _ = Nothing
134 toTypeSynonym _ = Nothing
135− toDataDecl (DataDeclaration _ nm args dctors) = Just (nm, args, dctors)
135+ toDataDecl (DataDeclaration dtype nm args dctors) = Just (dtype, nm, args, dctors)
136 toDataDecl (PositionedDeclaration _ d') = toDataDecl d'
136 toDataDecl (PositionedDeclaration _ d') = toDataDecl d'
137 toDataDecl _ = Nothing
137 toDataDecl _ = Nothing
138typeCheckAll mainModuleName moduleName (d@(TypeSynonymDeclaration name args ty) : rest) = do
138typeCheckAll mainModuleName moduleName (d@(TypeSynonymDeclaration name args ty) : rest) = do