2 % (c) The AQUA Project, Glasgow University, 1993-1995
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(..), RenamedDefaultDecl(..) )
15 import Inst ( InstOrigin(..) )
16 import TcEnv ( TcIdOcc, tcLookupClassByKey )
17 import TcMonoType ( tcHsType )
18 import TcSimplify ( tcSimplifyCheckThetas )
20 import TysWiredIn ( intTy, doubleTy, unitTy )
22 import Unique ( numClassKey )
23 import ErrUtils ( addShortErrLocLine )
29 default_default = [intTy, doubleTy] -- language-specified default `default'
31 tcDefaults :: [RenamedHsDecl]
32 -> TcM s [Type] -- defaulting types to heave
33 -- into Tc monad for later use
35 tcDefaults decls = tc_defaults [default_decl | DefD default_decl <- decls]
37 tc_defaults [] = returnTc default_default
39 tc_defaults [DefaultDecl mono_tys locn]
41 mapTc tcHsType mono_tys `thenTc` \ tau_tys ->
44 [] -> returnTc [] -- no defaults
47 -- Check that all the types are instances of Num
48 -- We only care about whether it worked or not
50 tcAddErrCtxt defaultDeclCtxt $
51 tcLookupClassByKey numClassKey `thenNF_Tc` \ num ->
54 [ (num, [ty]) | ty <- tau_tys ] `thenTc_`
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 = vcat (item1 : map dup_item dup_things)
70 = addShortErrLocLine locn1 (ptext SLIT("multiple default declarations"))
72 dup_item (DefaultDecl _ locn)
73 = addShortErrLocLine locn (ptext SLIT("here was another default declaration"))