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 Type ( SYN_IE(Type) )
28 import Unique ( numClassKey )
29 import Pretty ( ptext, vcat )
30 import ErrUtils ( addShortErrLocLine )
35 default_default = [intTy, doubleTy] -- language-specified default `default'
37 tcDefaults :: [RenamedHsDecl]
38 -> TcM s [Type] -- defaulting types to heave
39 -- into Tc monad for later use
41 tcDefaults decls = tc_defaults [default_decl | DefD default_decl <- decls]
43 tc_defaults [] = returnTc default_default
45 tc_defaults [DefaultDecl mono_tys locn]
47 mapTc tcHsType mono_tys `thenTc` \ tau_tys ->
50 [] -> returnTc [] -- no defaults
53 -- Check that all the types are instances of Num
54 -- We only care about whether it worked or not
56 tcLookupClassByKey numClassKey `thenNF_Tc` \ num ->
58 [ (num, ty) | ty <- tau_tys ] `thenTc_`
63 = failTc (dupDefaultDeclErr decls)
66 dupDefaultDeclErr (DefaultDecl _ locn1 : dup_things) sty
67 = vcat (item1 : map dup_item dup_things)
70 = addShortErrLocLine locn1 (\ sty ->
71 ptext SLIT("multiple default declarations")) sty
73 dup_item (DefaultDecl _ locn)
74 = addShortErrLocLine locn (\ sty ->
75 ptext SLIT("here was another default declaration")) sty