[project @ 1996-06-05 06:44:31 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 TcMonoType       ( tcMonoType )
22 import TcSimplify       ( tcSimplifyCheckThetas )
23
24 import TysWiredIn       ( intTy, doubleTy, unitTy )
25 import Unique           ( numClassKey )
26 import Util
27 \end{code}
28
29 \begin{code}
30 tcDefaults :: [RenamedDefaultDecl]
31            -> TcM s [Type]          -- defaulting types to heave
32                                     -- into Tc monad for later use
33                                     -- in Disambig.
34
35 tcDefaults []
36   = returnTc [intTy, doubleTy]      -- language-specified default `default'
37
38 tcDefaults [DefaultDecl mono_tys locn]
39   = tcAddSrcLoc locn $
40     mapTc tcMonoType mono_tys   `thenTc` \ tau_tys ->
41
42     case tau_tys of
43       [] -> returnTc []         -- no defaults
44
45       _  ->
46             -- Check that all the types are instances of Num
47             -- We only care about whether it worked or not
48
49         tcLookupClassByKey numClassKey                  `thenNF_Tc` \ num ->
50         tcSimplifyCheckThetas
51                 [ (num, ty) | ty <- tau_tys ]           `thenTc_`
52
53         returnTc tau_tys
54
55 \end{code}