2 % (c) The AQUA Project, Glasgow University, 1993-1995
4 \section[TcDefaults]{Typechecking \tr{default} declarations}
7 #include "HsVersions.h"
9 module TcDefaults ( tcDefaults ) where
13 import HsSyn ( HsDecl(..), TyDecl, ClassDecl, InstDecl, HsBinds,
14 DefaultDecl(..), HsType, IfaceSig,
15 HsExpr, HsLit, ArithSeqInfo, Fake, InPat)
16 import RnHsSyn ( RenamedHsDecl(..), RenamedDefaultDecl(..) )
17 import TcHsSyn ( TcIdOcc )
20 import Inst ( InstOrigin(..) )
21 import TcEnv ( tcLookupClassByKey )
22 import SpecEnv ( SpecEnv )
23 import TcMonoType ( tcHsType )
24 import TcSimplify ( tcSimplifyCheckThetas )
26 import TysWiredIn ( intTy, doubleTy, unitTy )
27 import Unique ( numClassKey )
28 import Pretty ( ppPStr, ppAboves )
29 import ErrUtils ( addShortErrLocLine )
34 default_default = [intTy, doubleTy] -- language-specified default `default'
36 tcDefaults :: [RenamedHsDecl]
37 -> TcM s [Type] -- defaulting types to heave
38 -- into Tc monad for later use
40 tcDefaults decls = tc_defaults [default_decl | DefD default_decl <- decls]
42 tc_defaults [] = returnTc default_default
44 tc_defaults [DefaultDecl mono_tys locn]
46 mapTc tcHsType mono_tys `thenTc` \ tau_tys ->
49 [] -> returnTc [] -- no defaults
52 -- Check that all the types are instances of Num
53 -- We only care about whether it worked or not
55 tcLookupClassByKey numClassKey `thenNF_Tc` \ num ->
57 [ (num, ty) | ty <- tau_tys ] `thenTc_`
62 = failTc (dupDefaultDeclErr decls)
65 dupDefaultDeclErr (DefaultDecl _ locn1 : dup_things) sty
66 = ppAboves (item1 : map dup_item dup_things)
69 = addShortErrLocLine locn1 (\ sty ->
70 ppPStr SLIT("multiple default declarations")) sty
72 dup_item (DefaultDecl _ locn)
73 = addShortErrLocLine locn (\ sty ->
74 ppPStr SLIT("here was another default declaration")) sty