2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
4 \section[TcGRHSs]{Typecheck guarded right-hand-sides}
7 module TcGRHSs ( tcGRHSsAndBinds ) where
9 import TcMonad -- typechecking monad machinery
10 import AbsSyn -- the stuff being typechecked
12 import AbsPrel ( boolTy )
13 import E ( growE_LVE, E, LVE(..), TCE(..), UniqFM, CE(..) )
14 -- TCE and CE for pragmas only
15 import Errors ( UnifyErrContext(..) )
16 import LIE ( plusLIE, LIE )
17 import TcBinds ( tcLocalBindsAndThen )
18 import TcExpr ( tcExpr )
19 import Unify ( unifyTauTy )
20 import Util -- pragmas only
24 tcGRHSs :: E -> [RenamedGRHS] -> TcM ([TypecheckedGRHS], LIE, UniType)
27 = tcGRHS e grhs `thenTc` \ (grhs', lie, ty) ->
28 returnTc ([grhs'], lie, ty)
30 tcGRHSs e gs@(grhs:grhss)
31 = tcGRHS e grhs `thenTc` \ (grhs', lie1, ty1) ->
32 tcGRHSs e grhss `thenTc` \ (grhss', lie2, ty2) ->
34 unifyTauTy ty1 ty2 (GRHSsBranchCtxt gs) `thenTc_`
36 returnTc (grhs' : grhss', lie1 `plusLIE` lie2, ty1)
39 tcGRHS e (OtherwiseGRHS expr locn)
41 tcExpr e expr `thenTc` \ (expr, lie, ty) ->
42 returnTc (OtherwiseGRHS expr locn, lie, ty)
45 tcGRHS e (GRHS guard expr locn)
47 tcExpr e guard `thenTc` \ (guard2, guard_lie, guard_ty) ->
49 unifyTauTy guard_ty boolTy (GRHSsGuardCtxt guard) `thenTc_`
51 tcExpr e expr `thenTc` \ (expr2, expr_lie, expr_ty) ->
53 returnTc (GRHS guard2 expr2 locn, plusLIE guard_lie expr_lie, expr_ty)
58 @tcGRHSsAndBinds@ typechecks (grhss where binds), returning suitable
63 -> RenamedGRHSsAndBinds
64 -> TcM (TypecheckedGRHSsAndBinds, LIE, UniType)
66 tcGRHSsAndBinds e (GRHSsAndBindsIn grhss binds)
67 = tcLocalBindsAndThen e
69 (\e -> tcGRHSs e grhss `thenTc` (\ (grhss', lie, ty) ->
70 returnTc (GRHSsAndBindsOut grhss' EmptyBinds ty, lie, ty)
74 combiner binds1 (GRHSsAndBindsOut grhss binds2 ty)
75 = GRHSsAndBindsOut grhss (binds1 `ThenBinds` binds2) ty