@@ -129,15 +129,17 @@ typeDictionaryForBindingGroup moduleName vals = do
130checkTypedBindingGroupElement :: ModuleName -> (Ident, (Expr, Type, Bool)) -> TypeData -> UnifyT Type Check (Ident, (Expr, Type))
130checkTypedBindingGroupElement :: ModuleName -> (Ident, (Expr, Type, Bool)) -> TypeData -> UnifyT Type Check (Ident, (Expr, Type))
131checkTypedBindingGroupElement moduleName (ident, (val', ty, checkType)) dict = do
131checkTypedBindingGroupElement moduleName (ident, (val', ty, checkType)) dict = do
132+ -- Replace type wildcards
133+ ty' <- replaceTypeWildcards ty
132 -- Kind check
134 -- Kind check
133 kind <- liftCheck $ kindOf moduleName ty
135 kind <- liftCheck $ kindOf moduleName ty
134 guardWith (strMsg $ "Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
136 guardWith (strMsg $ "Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
135 -- Check the type with the new names in scope
137 -- Check the type with the new names in scope
136− ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
138+ ty'' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty'
137 val'' <- if checkType
139 val'' <- if checkType
138− then bindNames dict $ TypedValue True <$> check val' ty' <*> pure ty'
140+ then bindNames dict $ TypedValue True <$> check val' ty'' <*> pure ty''
139− else return (TypedValue False val' ty')
141+ else return (TypedValue False val' ty'')
140− return (ident, (val'', ty'))
142+ return (ident, (val'', ty''))
142typeForBindingGroupElement :: (Ident, Expr) -> TypeData -> UntypedData -> UnifyT Type Check (Ident, (Expr, Type))
144typeForBindingGroupElement :: (Ident, Expr) -> TypeData -> UntypedData -> UnifyT Type Check (Ident, (Expr, Type))
143typeForBindingGroupElement (ident, val) dict untypedDict = do
145typeForBindingGroupElement (ident, val) dict untypedDict = do
@@ -259,7 +261,7 @@ infer' (App f arg) = do
259infer' (Var var) = do
261infer' (Var var) = do
260 Just moduleName <- checkCurrentModule <$> get
262 Just moduleName <- checkCurrentModule <$> get
261 checkVisibility moduleName var
263 checkVisibility moduleName var
262− ty <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< lookupVariable moduleName $ var
264+ ty <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards <=< lookupVariable moduleName $ var
263 case ty of
265 case ty of
264 ConstrainedType constraints ty' -> do
266 ConstrainedType constraints ty' -> do
265 dicts <- getTypeClassDictionaries
267 dicts <- getTypeClassDictionaries
@@ -291,7 +293,7 @@ infer' (SuperClassDictionary className tys) = do
291infer' (TypedValue checkType val ty) = do
293infer' (TypedValue checkType val ty) = do
292 Just moduleName <- checkCurrentModule <$> get
294 Just moduleName <- checkCurrentModule <$> get
293 checkTypeKind moduleName ty
295 checkTypeKind moduleName ty
294− ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
296+ ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty
295 val' <- if checkType then check val ty' else return val
297 val' <- if checkType then check val ty' else return val
296 return $ TypedValue True val' ty'
298 return $ TypedValue True val' ty'
297infer' (PositionedValue pos val) = rethrowWithPosition pos $ infer' val
299infer' (PositionedValue pos val) = rethrowWithPosition pos $ infer' val
@@ -303,7 +305,7 @@ inferLetBinding seen (ValueDeclaration ident nameKind [] (Right (tv@(TypedValue
303 Just moduleName <- checkCurrentModule <$> get
305 Just moduleName <- checkCurrentModule <$> get
304 checkTypeKind moduleName ty
306 checkTypeKind moduleName ty
305 let dict = M.singleton (moduleName, ident) (ty, nameKind, Undefined)
307 let dict = M.singleton (moduleName, ident) (ty, nameKind, Undefined)
306− ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
308+ ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty
307 TypedValue _ val' ty'' <- if checkType then bindNames dict (check val ty') else return tv
309 TypedValue _ val' ty'' <- if checkType then bindNames dict (check val ty') else return tv
308 bindNames (M.singleton (moduleName, ident) (ty'', nameKind, Defined)) $ inferLetBinding (seen ++ [ValueDeclaration ident nameKind [] (Right (TypedValue checkType val' ty''))]) rest ret j
310 bindNames (M.singleton (moduleName, ident) (ty'', nameKind, Defined)) $ inferLetBinding (seen ++ [ValueDeclaration ident nameKind [] (Right (TypedValue checkType val' ty''))]) rest ret j
309inferLetBinding seen (ValueDeclaration ident nameKind [] (Right val) : rest) ret j = do
311inferLetBinding seen (ValueDeclaration ident nameKind [] (Right val) : rest) ret j = do
@@ -483,7 +485,7 @@ check' v@(Var var) ty = do
483 Just moduleName <- checkCurrentModule <$> get
485 Just moduleName <- checkCurrentModule <$> get
484 checkVisibility moduleName var
486 checkVisibility moduleName var
485 repl <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< lookupVariable moduleName $ var
487 repl <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< lookupVariable moduleName $ var
486− ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty
488+ ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty
487 v' <- subsumes (Just v) repl ty'
489 v' <- subsumes (Just v) repl ty'
488 case v' of
490 case v' of
489 Nothing -> throwError . strMsg $ "Unable to check type subsumption"
491 Nothing -> throwError . strMsg $ "Unable to check type subsumption"
@@ -504,8 +506,8 @@ check' (SuperClassDictionary className tys) _ = do
504check' (TypedValue checkType val ty1) ty2 = do
506check' (TypedValue checkType val ty1) ty2 = do
505 Just moduleName <- checkCurrentModule <$> get
507 Just moduleName <- checkCurrentModule <$> get
506 checkTypeKind moduleName ty1
508 checkTypeKind moduleName ty1
507− ty1' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
509+ ty1' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty1
508− ty2' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty2
510+ ty2' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty2
509 val' <- subsumes (Just val) ty1' ty2'
511 val' <- subsumes (Just val) ty1' ty2'
510 case val' of
512 case val' of
511 Nothing -> throwError . strMsg $ "Unable to check type subsumption"
513 Nothing -> throwError . strMsg $ "Unable to check type subsumption"
@@ -555,7 +557,7 @@ check' (Let ds val) ty = do
555 (ds', val') <- inferLetBinding [] ds val (`check` ty)
557 (ds', val') <- inferLetBinding [] ds val (`check` ty)
556 return $ TypedValue True (Let ds' val') ty
558 return $ TypedValue True (Let ds' val') ty
557check' val ty | containsTypeSynonyms ty = do
559check' val ty | containsTypeSynonyms ty = do
558− ty' <- introduceSkolemScope <=< expandAllTypeSynonyms $ ty
560+ ty' <- introduceSkolemScope <=< expandAllTypeSynonyms <=< replaceTypeWildcards $ ty
559 check val ty'
561 check val ty'
560check' val kt@(KindedType ty kind) = do
562check' val kt@(KindedType ty kind) = do
561 guardWith (strMsg $ "Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
563 guardWith (strMsg $ "Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star