From 924f851700ca9ba7e0e7483b7ca4de62a4a74e15 Mon Sep 17 00:00:00 2001 From: Simon Peyton Jones Date: Wed, 25 Nov 2015 16:26:23 +0000 Subject: Refactor default methods (Trac #11105) This patch does some signficant refactoring to the treatment of default methods in class declarations, and more generally to the type checking of type/class decls. Highlights: * When the class has a generic-default method, such as class C a where op :: a -> a -> Bool default op :: Ord a => a -> a -> a the ClassOpItem records the type of the generic-default, in this case the type (Ord a => a -> a -> a) * I killed off Class.DefMeth in favour of the very-similar BasicTypes.DefMethSpec. However it turned out to be better to use a Maybe, thus Maybe (DefMethSpec Type) with Nothing meaning "no default method". * In TcTyClsDecls.tcTyClGroup, we used to accumulate a [TyThing], but I found a way to make it much simpler, accumulating only a [TyCon]. Much less wrapping and unwrapping. * On the way I also fixed Trac #10896 in a better way. Instead of killing off all ambiguity checks whenever there are any type errors (the fix in commit 8e8b9ed), I instead recover in TcTyClsDecls.checkValidTyCl. There was a lot of associated simplification all round --- compiler/iface/MkIface.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'compiler/iface/MkIface.hs') diff --git a/compiler/iface/MkIface.hs b/compiler/iface/MkIface.hs index 98b8830e01..d955fa5fd9 100644 --- a/compiler/iface/MkIface.hs +++ b/compiler/iface/MkIface.hs @@ -1529,8 +1529,9 @@ classToIfaceDecl env clas toIfaceClassOp (sel_id, def_meth) = ASSERT(sel_tyvars == clas_tyvars) - IfaceClassOp (getOccName sel_id) (toDmSpec def_meth) + IfaceClassOp (getOccName sel_id) (tidyToIfaceType env1 op_ty) + (fmap toDmSpec def_meth) where -- Be careful when splitting the type, because of things -- like class Foo a where @@ -1540,9 +1541,9 @@ classToIfaceDecl env clas (sel_tyvars, rho_ty) = splitForAllTys (idType sel_id) op_ty = funResultTy rho_ty - toDmSpec NoDefMeth = NoDM - toDmSpec (GenDefMeth _) = GenericDM - toDmSpec (DefMeth _) = VanillaDM + toDmSpec :: (Name, DefMethSpec Type) -> DefMethSpec IfaceType + toDmSpec (_, VanillaDM) = VanillaDM + toDmSpec (_, GenericDM dm_ty) = GenericDM (tidyToIfaceType env1 dm_ty) toIfaceFD (tvs1, tvs2) = (map (getFS . tidyTyVar env1) tvs1, map (getFS . tidyTyVar env1) tvs2) -- cgit v1.2.1