@@ -67,24 +67,17 @@ import Language.PureScript.TypeChecker.Synonyms
67import Language.PureScript.TypeChecker.Unify
67import Language.PureScript.TypeChecker.Unify
68import Language.PureScript.TypeClassDictionaries
68import Language.PureScript.TypeClassDictionaries
69import Language.PureScript.Types
69import Language.PureScript.Types
70−import qualified Language.PureScript.Constants as C
73-- Infer the types of multiple mutually-recursive values, and return elaborated values including
72-- Infer the types of multiple mutually-recursive values, and return elaborated values including
74-- type class dictionaries and type annotations.
73-- type class dictionaries and type annotations.
76−typesOf :: Maybe ModuleName -> ModuleName -> [(Ident, Expr)] -> Check [(Ident, (Expr, Type))]
75+typesOf :: ModuleName -> [(Ident, Expr)] -> Check [(Ident, (Expr, Type))]
77−typesOf mainModuleName moduleName vals = do
76+typesOf moduleName vals = do
78 tys <- fmap tidyUp . liftUnifyWarnings replace $ do
77 tys <- fmap tidyUp . liftUnifyWarnings replace $ do
79 (untyped, typed, dict, untypedDict) <- typeDictionaryForBindingGroup moduleName vals
78 (untyped, typed, dict, untypedDict) <- typeDictionaryForBindingGroup moduleName vals
80− ds1 <- parU typed $ \e -> do
81− triple@(_, (_, ty)) <- checkTypedBindingGroupElement moduleName e dict
79+ ds1 <- parU typed $ \e -> checkTypedBindingGroupElement moduleName e dict
84− ds2 <- forM untyped $ \e -> do
85− triple@(_, (_, ty)) <- typeForBindingGroupElement e dict untypedDict
80+ ds2 <- forM untyped $ \e -> typeForBindingGroupElement e dict untypedDict
88 return $ ds1 ++ ds2
81 return $ ds1 ++ ds2
90 forM tys $ \(ident, (val, ty)) -> do
83 forM tys $ \(ident, (val, ty)) -> do
@@ -94,21 +87,13 @@ typesOf mainModuleName moduleName vals = do
94 skolemEscapeCheck val'
87 skolemEscapeCheck val'
95 -- Check rows do not contain duplicate labels
88 -- Check rows do not contain duplicate labels
96 checkDuplicateLabels val'
89 checkDuplicateLabels val'
97− -- Remove type synonyms placeholders, and replace
98− -- top-level unification variables with named type variables.
99− let val'' = overTypes desaturateAllTypeSynonyms val'
100− ty' = varIfUnknown . desaturateAllTypeSynonyms $ ty
101− return (ident, (val'', ty'))
90+ return (ident, (val', varIfUnknown ty))
103 -- Apply the substitution that was returned from runUnify to both types and (type-annotated) values
92 -- Apply the substitution that was returned from runUnify to both types and (type-annotated) values
104 tidyUp (ts, sub) = map (\(i, (val, ty)) -> (i, (overTypes (sub $?) val, sub $? ty))) ts
93 tidyUp (ts, sub) = map (\(i, (val, ty)) -> (i, (overTypes (sub $?) val, sub $? ty))) ts
105 -- Replace all the wildcards types with their inferred types
94 -- Replace all the wildcards types with their inferred types
106 replace sub (SimpleErrorWrapper (WildcardInferredType ty)) = SimpleErrorWrapper $ WildcardInferredType (sub $? ty)
95 replace sub (SimpleErrorWrapper (WildcardInferredType ty)) = SimpleErrorWrapper $ WildcardInferredType (sub $? ty)
107 replace _ em = em
96 replace _ em = em
108− -- If --main is enabled, need to check that `main` has type Eff eff a for some eff, a
109− checkMain nm ty = when (Just moduleName == mainModuleName && nm == Ident C.main) $ do
110− [eff, a] <- replicateM 2 fresh
111− ty =?= TypeApp (TypeApp (TypeConstructor (Qualified (Just (ModuleName [ProperName "Control", ProperName "Monad", ProperName "Eff"])) (ProperName "Eff"))) eff) a
113type TypeData = M.Map (ModuleName, Ident) (Type, NameKind, NameVisibility)
98type TypeData = M.Map (ModuleName, Ident) (Type, NameKind, NameVisibility)
@@ -346,9 +331,6 @@ inferProperty :: Type -> String -> UnifyT Type Check (Maybe Type)
346inferProperty (TypeApp obj row) prop | obj == tyObject = do
331inferProperty (TypeApp obj row) prop | obj == tyObject = do
347 let (props, _) = rowToList row
332 let (props, _) = rowToList row
348 return $ lookup prop props
333 return $ lookup prop props
349−inferProperty (SaturatedTypeSynonym name args) prop = do
350− replaced <- introduceSkolemScope <=< expandTypeSynonym name $ args
351− inferProperty replaced prop
352inferProperty (ForAll ident ty _) prop = do
334inferProperty (ForAll ident ty _) prop = do
353 replaced <- replaceVarWithUnknown ident ty
335 replaced <- replaceVarWithUnknown ident ty
354 inferProperty replaced prop
336 inferProperty replaced prop
@@ -493,9 +475,6 @@ check' val t@(ConstrainedType constraints ty) = do
494 instantiateSuperclass :: [String] -> [Type] -> [Type] -> [Type]
476 instantiateSuperclass :: [String] -> [Type] -> [Type] -> [Type]
495 instantiateSuperclass args supArgs tys = map (replaceAllTypeVars (zip args tys)) supArgs
477 instantiateSuperclass args supArgs tys = map (replaceAllTypeVars (zip args tys)) supArgs
496−check' val (SaturatedTypeSynonym name args) = do
497− ty <- introduceSkolemScope <=< expandTypeSynonym name $ args
499check' val u@(TUnknown _) = do
478check' val u@(TUnknown _) = do
500 val'@(TypedValue _ _ ty) <- infer val
479 val'@(TypedValue _ _ ty) <- infer val
501 -- Don't unify an unknown with an inferred polytype
480 -- Don't unify an unknown with an inferred polytype
@@ -674,9 +653,6 @@ checkFunctionApplication' fn u@(TUnknown _) arg ret = do
674 ret' <- maybe fresh return ret
653 ret' <- maybe fresh return ret
675 u =?= function ty ret'
654 u =?= function ty ret'
676 return (ret', App fn arg')
655 return (ret', App fn arg')
677−checkFunctionApplication' fn (SaturatedTypeSynonym name tyArgs) arg ret = do
678− ty <- introduceSkolemScope <=< expandTypeSynonym name $ tyArgs
679− checkFunctionApplication fn ty arg ret
680checkFunctionApplication' fn (KindedType ty _) arg ret =
656checkFunctionApplication' fn (KindedType ty _) arg ret =
681 checkFunctionApplication fn ty arg ret
657 checkFunctionApplication fn ty arg ret
682checkFunctionApplication' fn (ConstrainedType constraints fnTy) arg ret = do
658checkFunctionApplication' fn (ConstrainedType constraints fnTy) arg ret = do