X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Ftypecheck%2FTcDefaults.lhs;h=50b5767cef93614c00d88330f39d0e26931392bb;hp=43f23a329ed6cf4b991cdb46f5e460a9761e67a0;hb=HEAD;hpb=7fc749a43b4b6b85d234fa95d4928648259584f4 diff --git a/compiler/typecheck/TcDefaults.lhs b/compiler/typecheck/TcDefaults.lhs index 43f23a3..50b5767 100644 --- a/compiler/typecheck/TcDefaults.lhs +++ b/compiler/typecheck/TcDefaults.lhs @@ -5,17 +5,8 @@ \section[TcDefaults]{Typechecking \tr{default} declarations} \begin{code} -{-# OPTIONS -w #-} --- The above warning supression flag is a temporary kludge. --- While working on this module you are encouraged to remove it and fix --- any warnings in the module. See --- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings --- for details - module TcDefaults ( tcDefaults ) where -#include "HsVersions.h" - import HsSyn import Name import Class @@ -27,8 +18,9 @@ import TcType import PrelNames import DynFlags import SrcLoc -import Maybe +import Data.Maybe import Outputable +import FastString \end{code} \begin{code} @@ -49,19 +41,19 @@ tcDefaults [] -- one group, only for the next group to ignore them and install -- defaultDefaultTys -tcDefaults [L locn (DefaultDecl [])] - = returnM (Just []) -- Default declaration specifying no types +tcDefaults [L _ (DefaultDecl [])] + = return (Just []) -- Default declaration specifying no types tcDefaults [L locn (DefaultDecl mono_tys)] = setSrcSpan locn $ addErrCtxt defaultDeclCtxt $ - do { ovl_str <- doptM Opt_OverloadedStrings + do { ovl_str <- xoptM Opt_OverloadedStrings ; num_class <- tcLookupClass numClassName ; is_str_class <- tcLookupClass isStringClassName ; let deflt_clss | ovl_str = [num_class, is_str_class] | otherwise = [num_class] - ; tau_tys <- mappM (tc_default_ty deflt_clss) mono_tys + ; tau_tys <- mapM (tc_default_ty deflt_clss) mono_tys ; return (Just tau_tys) } @@ -70,6 +62,7 @@ tcDefaults decls@(L locn (DefaultDecl _) : _) failWithTc (dupDefaultDeclErr decls) +tc_default_ty :: [Class] -> LHsType Name -> TcM Type tc_default_ty deflt_clss hs_ty = do { ty <- tcHsSigType DefaultDeclCtxt hs_ty ; checkTc (isTauTy ty) (polyDefErr hs_ty) @@ -83,22 +76,27 @@ check_instance :: Type -> Class -> TcM Bool -- Check that ty is an instance of cls -- We only care about whether it worked or not; return a boolean check_instance ty cls - = do { (_, mb_res) <- tryTc (tcSimplifyDefault [mkClassPred cls [ty]]) + = do { (_, mb_res) <- tryTc (simplifyDefault [mkClassPred cls [ty]]) ; return (isJust mb_res) } -defaultDeclCtxt = ptext SLIT("When checking the types in a default declaration") +defaultDeclCtxt :: SDoc +defaultDeclCtxt = ptext (sLit "When checking the types in a default declaration") +dupDefaultDeclErr :: [Located (DefaultDecl Name)] -> SDoc dupDefaultDeclErr (L _ (DefaultDecl _) : dup_things) - = hang (ptext SLIT("Multiple default declarations")) - 4 (vcat (map pp dup_things)) + = hang (ptext (sLit "Multiple default declarations")) + 2 (vcat (map pp dup_things)) where - pp (L locn (DefaultDecl _)) = ptext SLIT("here was another default declaration") <+> ppr locn + pp (L locn (DefaultDecl _)) = ptext (sLit "here was another default declaration") <+> ppr locn +dupDefaultDeclErr [] = panic "dupDefaultDeclErr []" +polyDefErr :: LHsType Name -> SDoc polyDefErr ty - = hang (ptext SLIT("Illegal polymorphic type in default declaration") <> colon) 4 (ppr ty) + = hang (ptext (sLit "Illegal polymorphic type in default declaration") <> colon) 2 (ppr ty) +badDefaultTy :: Type -> [Class] -> SDoc badDefaultTy ty deflt_clss - = hang (ptext SLIT("The default type") <+> quotes (ppr ty) <+> ptext SLIT("is not an instance of")) - 2 (foldr1 (\a b -> a <+> ptext SLIT("or") <+> b) (map (quotes. ppr) deflt_clss)) + = hang (ptext (sLit "The default type") <+> quotes (ppr ty) <+> ptext (sLit "is not an instance of")) + 2 (foldr1 (\a b -> a <+> ptext (sLit "or") <+> b) (map (quotes. ppr) deflt_clss)) \end{code}