-checkTyApp :: UniType
- -> [UniType]
- -> ErrMsg
- -> LintM (Maybe UniType)
-
-checkTyApp forall_ty ty_args msg spec_done loc scope errs
- = if (not spec_done && n_ty_args /= n_tyvars)
- || (spec_done && n_ty_args > n_tyvars)
- --
- -- Things are *not* OK if:
- --
- -- * Unsaturated type app before specialisation has been done;
- --
- -- * Oversaturated type app after specialisation (eta reduction
- -- may well be happening...);
- --
- -- Note: checkTyApp is usually followed by a call to checkSpecTyApp.
- --
- then (Nothing, addErr errs msg loc)
- else (Just res_ty, errs)
- where
- (tyvars, rho_ty) = splitForalls forall_ty
- n_tyvars = length tyvars
- n_ty_args = length ty_args
- leftover_tyvars = drop n_ty_args tyvars
- inst_env = tyvars `zip` ty_args
- res_ty = mkForallTy leftover_tyvars (instantiateTy inst_env rho_ty)
-\end{code}
-
-\begin{code}
-checkSpecTyApp :: PlainCoreExpr -> [UniType] -> ErrMsg -> LintM (Maybe ())
-
-checkSpecTyApp expr ty_args msg spec_done loc scope errs
- = if spec_done
- && any isUnboxedDataType ty_args
- && not (an_application_of_error expr)
- then (Nothing, addErr errs msg loc)
- else (Just (), errs)
- where
- -- always safe (but maybe unfriendly) to say "False"
- an_application_of_error (CoVar id) | isBottomingId id = True
- an_application_of_error _ = False
-\end{code}
-
-\begin{code}
-checkFunApp :: UniType -- The function type
- -> [UniType] -- The arg type(s)
- -> ErrMsg -- Error messgae
- -> LintM (Maybe UniType) -- The result type
-
-checkFunApp fun_ty arg_tys msg spec loc scope errs
- = cfa res_ty expected_arg_tys arg_tys
- where
- (expected_arg_tys, res_ty) = splitTyArgs fun_ty
-
- cfa res_ty expected [] -- Args have run out; that's fine
- = (Just (glueTyArgs expected res_ty), errs)
-
- cfa res_ty [] arg_tys -- Expected arg tys ran out first; maybe res_ty is a
- -- dictionary type which is actually a function?
- = case splitTyArgs (unDictifyTy res_ty) of
- ([], _) -> (Nothing, addErr errs msg loc) -- Too many args
- (new_expected, new_res) -> cfa new_res new_expected arg_tys
-
- cfa res_ty (expected_arg_ty:expected_arg_tys) (arg_ty:arg_tys)
- = case (cmpUniType True{-properly-} expected_arg_ty arg_ty) of
- EQ_ -> cfa res_ty expected_arg_tys arg_tys
- other -> (Nothing, addErr errs msg loc) -- Arg mis-match
-\end{code}
-
-\begin{code}