returnTc (tycon_name, SynTyDetails rhs_ty)
-tcTyDecl1 (TyData _ context tycon_name _ con_decls _ derivings _ src_loc)
+tcTyDecl1 (TyData new_or_data context tycon_name _ con_decls _ derivings _ src_loc)
= tcLookupTy tycon_name `thenNF_Tc` \ (ATyCon tycon) ->
let
tyvars = tyConTyVars tycon
tcExtendTyVarEnv tyvars $
-- Typecheck the pieces
- tcClassContext context `thenTc` \ ctxt ->
- tc_derivs derivings `thenTc` \ derived_classes ->
- mapTc (tcConDecl tycon tyvars ctxt) con_decls `thenTc` \ data_cons ->
+ tcClassContext context `thenTc` \ ctxt ->
+ tc_derivs derivings `thenTc` \ derived_classes ->
+ mapTc (tcConDecl new_or_data tycon tyvars ctxt) con_decls `thenTc` \ data_cons ->
returnTc (tycon_name, DataTyDetails ctxt data_cons derived_classes)
where
where
kc_con_details (VanillaCon btys) = mapTc_ kc_bty btys
kc_con_details (InfixCon bty1 bty2) = mapTc_ kc_bty [bty1,bty2]
- kc_con_details (NewCon ty _) = kcHsSigType ty
kc_con_details (RecCon flds) = mapTc_ kc_field flds
kc_field (_, bty) = kc_bty bty
kc_bty bty = kcHsSigType (getBangType bty)
-tcConDecl :: TyCon -> [TyVar] -> ClassContext -> RenamedConDecl -> TcM s DataCon
+tcConDecl :: NewOrData -> TyCon -> [TyVar] -> ClassContext -> RenamedConDecl -> TcM s DataCon
-tcConDecl tycon tyvars ctxt (ConDecl name wkr_name ex_tvs ex_ctxt details src_loc)
+tcConDecl new_or_data tycon tyvars ctxt (ConDecl name wkr_name ex_tvs ex_ctxt details src_loc)
= tcAddSrcLoc src_loc $
kcTyVarScope ex_tvs (kcConDetails ex_ctxt details) `thenTc` \ ex_tv_kinds ->
let
case details of
VanillaCon btys -> tc_datacon ex_tyvars ex_theta btys
InfixCon bty1 bty2 -> tc_datacon ex_tyvars ex_theta [bty1,bty2]
- NewCon ty mb_f -> tc_newcon ex_tyvars ex_theta ty mb_f
RecCon fields -> tc_rec_con ex_tyvars ex_theta fields
where
+ tc_sig_type = case new_or_data of
+ DataType -> tcHsSigType
+ NewType -> tcHsBoxedSigType
+ -- Can't allow an unboxed type here, because we're effectively
+ -- going to remove the constructor while coercing it to a boxed type.
+
tc_datacon ex_tyvars ex_theta btys
= let
arg_stricts = map getBangStrictness btys
tys = map getBangType btys
in
- mapTc tcHsSigType tys `thenTc` \ arg_tys ->
+ mapTc tc_sig_type tys `thenTc` \ arg_tys ->
mk_data_con ex_tyvars ex_theta arg_stricts arg_tys []
- tc_newcon ex_tyvars ex_theta ty mb_f
- = tcHsBoxedSigType ty `thenTc` \ arg_ty ->
- -- can't allow an unboxed type here, because we're effectively
- -- going to remove the constructor while coercing it to a boxed type.
- let
- field_label =
- case mb_f of
- Nothing -> []
- Just f -> [mkFieldLabel (getName f) tycon arg_ty (head allFieldLabelTags)]
- in
- mk_data_con ex_tyvars ex_theta [notMarkedStrict] [arg_ty] field_label
-
tc_rec_con ex_tyvars ex_theta fields
= checkTc (null ex_tyvars) (exRecConErr name) `thenTc_`
mapTc tc_field (fields `zip` allFieldLabelTags) `thenTc` \ field_labels_s ->
(map fieldLabelType field_labels) field_labels
tc_field ((field_label_names, bty), tag)
- = tcHsSigType (getBangType bty) `thenTc` \ field_ty ->
+ = tc_sig_type (getBangType bty) `thenTc` \ field_ty ->
returnTc [mkFieldLabel (getName name) tycon field_ty tag | name <- field_label_names]
mk_data_con ex_tyvars ex_theta arg_stricts arg_tys fields