@@ -20,8 +20,7 @@ module Language.PureScript.TypeChecker.Types (
2020) where
2121
2222import Data.List
23−import Data.Maybe (fromMaybe)
24−import Data.Either (lefts, rights)
23+import Data.Maybe (isNothing, isJust, fromMaybe)
2524import qualified Data.Data as D
2625import Data.Generics
2726 (mkT, something, everywhere, everywhereBut, mkQ)
@@ -146,31 +145,36 @@ typesOf :: ModuleName -> [(Ident, Value)] -> Check [Type]
146145typesOf moduleName vals = do
147146 (tys, sub, checks) <- runSubst (SubstContext moduleName) $ do
148147 let es = map isTyped vals
149− typed = lefts es
150− untyped = rights es
151− typedDict = map (\(ident, ty, _) -> (ident, ty)) typed
148+ typed = filter (isJust . snd . snd) es
149+ untyped = filter (isNothing . snd . snd) es
150+ typedDict = map (\(ident, (_, Just ty)) -> (ident, ty)) typed
152151 untypedNames <- replicateM (length untyped) fresh
153152 let untypedDict = zip (map fst untyped) untypedNames
154153 dict = M.fromList (map (\(ident, ty) -> ((moduleName, ident), (ty, LocalVariable))) $ typedDict ++ untypedDict)
155− tys <- forM es $ \e -> case e of
156− Left (_, ty, val) -> do
157− kind <- liftCheck $ kindOf moduleName ty
158− guardWith ("Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
159− ty' <- replaceAllTypeSynonyms ty
160− bindNames dict $ check val ty'
161− return ty'
162− Right (ident, val) -> do
163− ty <- bindNames dict $ infer val
164− ty ~~ fromMaybe (error "name not found in dictionary") (lookup ident untypedDict)
165− return ty
154+ tys <- forM es $ \e -> do
155+ ty <- case e of
156+ (_, (val, Just ty)) -> do
157+ kind <- liftCheck $ kindOf moduleName ty
158+ guardWith ("Expected type of kind *, was " ++ prettyPrintKind kind) $ kind == Star
159+ ty' <- replaceAllTypeSynonyms ty
160+ bindNames dict $ check val ty'
161+ return ty'
162+ (ident, (val, Nothing)) -> do
163+ ty <- bindNames dict $ infer val
164+ ty ~~ fromMaybe (error "name not found in dictionary") (lookup ident untypedDict)
165+ return ty
166+ when (moduleName == ModuleName (ProperName "Main") && fst e == Ident "main") $ do
167+ [eff, a] <- replicateM 2 fresh
168+ ty ~~ TypeApp (TypeApp (TypeConstructor (Qualified (Just (ModuleName (ProperName "Eff"))) (ProperName "Eff"))) eff) a
169+ return ty
166170 return tys
167171 forM tys $ flip (escapeCheck checks) sub
168172 forM tys $ skolemEscapeCheck
169173 return $ map (varIfUnknown . desaturateAllTypeSynonyms . setifyAll) tys
170174
171−isTyped :: (Ident, Value) -> Either (Ident, Type, Value) (Ident, Value)
172−isTyped (name, TypedValue value ty) = Left (name, ty, value)
173−isTyped (name, value) = Right (name, value)
175+isTyped :: (Ident, Value) -> (Ident, (Value, Maybe Type))
176+isTyped (name, TypedValue value ty) = (name, (value, Just ty))
177+isTyped (name, value) = (name, (value, Nothing))
174178
175179escapeCheck :: [AnyUnifiable] -> Type -> Substitution -> Check ()
176180escapeCheck checks ty sub =