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
14 import AbsPrel ( intTy, doubleTy, unitTy )
15 import AbsUniType ( UniType
16 IF_ATTACK_PRAGMAS(COMMA cmpUniType)
18 import CE ( lookupCE, CE(..) )
22 import TcMonoType ( tcMonoType )
23 import TcSimplify ( tcSimplifyCheckThetas )
25 import Unique ( numClassKey, Unique )
31 -> [RenamedDefaultDecl]
32 -> TcM [UniType] -- defaulting types to heave
33 -- into Tc monad for later use
37 = returnTc [intTy, doubleTy] -- language-specified default `default'
39 tcDefaults e [DefaultDecl mono_tys locn]
45 num_clas = lookupCE ce (PreludeClass numClassKey (panic "tcDefaults"))
47 babyTcMtoTcM (mapB_Tc (tcMonoType ce tce tve) mono_tys) `thenTc` \ tau_tys ->
49 -- compensate for extreme parser hack: `default ()' actually
50 -- sends the *type* () through to here. Squash it.
52 [ty] | ty == unitTy -> returnTc []
54 _ -> -- (Back to your regularly scheduled programming...)
56 -- Check that all the types are instances of Num
58 tcSimplifyCheckThetas (DefaultDeclOrigin locn)
59 [ (num_clas, ty) | ty <- tau_tys ] `thenTc` \ _ ->
60 -- We only care about whether it worked or not
62 returnTc tau_tys -- caller will bung them into Tc monad
65 = error "ERROR: You can only have one `default' declaration per module."
66 -- ToDo: proper error msg.