2 % (c) The AQUA Project, Glasgow University, 1993-1998
4 \section[TcDefaults]{Typechecking \tr{default} declarations}
7 module TcDefaults ( tcDefaults ) where
9 #include "HsVersions.h"
11 import HsSyn ( HsDecl(..), DefaultDecl(..) )
12 import RnHsSyn ( RenamedHsDecl )
15 import TcEnv ( tcLookupClassByKey )
16 import TcMonoType ( tcHsType )
17 import TcSimplify ( tcSimplifyCheckThetas )
19 import TysWiredIn ( integerTy, doubleTy )
21 import Unique ( numClassKey )
22 import ErrUtils ( addShortErrLocLine )
28 default_default = [integerTy, doubleTy ]
30 tcDefaults :: [RenamedHsDecl]
31 -> TcM s [Type] -- defaulting types to heave
32 -- into Tc monad for later use
34 tcDefaults decls = tc_defaults [default_decl | DefD default_decl <- decls]
36 tc_defaults [] = returnTc default_default
38 tc_defaults [DefaultDecl mono_tys locn]
40 mapTc tcHsType mono_tys `thenTc` \ tau_tys ->
43 [] -> returnTc [] -- no defaults
46 -- Check that all the types are instances of Num
47 -- We only care about whether it worked or not
49 tcAddErrCtxt defaultDeclCtxt $
50 tcLookupClassByKey numClassKey `thenNF_Tc` \ num ->
53 [ (num, [ty]) | ty <- tau_tys ] `thenTc_`
57 tc_defaults decls@(DefaultDecl _ loc : _) =
59 failWithTc (dupDefaultDeclErr decls)
62 defaultDeclCtxt = ptext SLIT("when checking that each type in a default declaration")
63 $$ ptext SLIT("is an instance of class Num")
66 dupDefaultDeclErr (DefaultDecl _ locn1 : dup_things)
67 = hang (ptext SLIT("Multiple default declarations"))
68 4 (vcat (map pp dup_things))
70 pp (DefaultDecl _ locn) = ptext SLIT("here was another default declaration") <+> ppr locn