[project @ 1996-07-15 16:16:46 by partain]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcDefaults.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1993-1995
3 %
4 \section[TcDefaults]{Typechecking \tr{default} declarations}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module TcDefaults ( tcDefaults ) where
10
11 IMP_Ubiq()
12
13 import HsSyn            ( DefaultDecl(..), MonoType,
14                           HsExpr, HsLit, ArithSeqInfo, Fake, InPat)
15 import RnHsSyn          ( RenamedDefaultDecl(..) )
16 import TcHsSyn          ( TcIdOcc )
17
18 import TcMonad          hiding ( rnMtoTcM )
19 import Inst             ( InstOrigin(..) )
20 import TcEnv            ( tcLookupClassByKey )
21 import SpecEnv          ( SpecEnv )
22 import TcMonoType       ( tcMonoType )
23 import TcSimplify       ( tcSimplifyCheckThetas )
24
25 import TysWiredIn       ( intTy, doubleTy, unitTy )
26 import Unique           ( numClassKey )
27 import Util
28 \end{code}
29
30 \begin{code}
31 tcDefaults :: [RenamedDefaultDecl]
32            -> TcM s [Type]          -- defaulting types to heave
33                                     -- into Tc monad for later use
34                                     -- in Disambig.
35
36 tcDefaults []
37   = returnTc [intTy, doubleTy]      -- language-specified default `default'
38
39 tcDefaults [DefaultDecl mono_tys locn]
40   = tcAddSrcLoc locn $
41     mapTc tcMonoType mono_tys   `thenTc` \ tau_tys ->
42
43     case tau_tys of
44       [] -> returnTc []         -- no defaults
45
46       _  ->
47             -- Check that all the types are instances of Num
48             -- We only care about whether it worked or not
49
50         tcLookupClassByKey numClassKey                  `thenNF_Tc` \ num ->
51         tcSimplifyCheckThetas
52                 [ (num, ty) | ty <- tau_tys ]           `thenTc_`
53
54         returnTc tau_tys
55
56 \end{code}