2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
4 \section[TcGRHSs]{Typecheck guarded right-hand-sides}
7 #include "HsVersions.h"
9 module TcGRHSs ( tcGRHSsAndBinds ) where
12 IMPORT_DELOOPER(TcLoop) -- for paranoia checking
14 import HsSyn ( GRHSsAndBinds(..), GRHS(..), MonoBinds, Stmt, DoOrListComp(..),
15 HsExpr, HsBinds(..), InPat, OutPat, Sig, Fake )
16 import RnHsSyn ( SYN_IE(RenamedGRHSsAndBinds), SYN_IE(RenamedGRHS) )
17 import TcHsSyn ( SYN_IE(TcGRHSsAndBinds), SYN_IE(TcGRHS), TcIdOcc(..) )
20 import Inst ( Inst, SYN_IE(LIE), plusLIE )
21 import TcBinds ( tcBindsAndThen )
22 import TcExpr ( tcExpr, tcStmt )
23 import TcType ( SYN_IE(TcType) )
24 import Unify ( unifyTauTy )
26 import TysWiredIn ( boolTy )
30 tcGRHSs :: [RenamedGRHS] -> TcM s ([TcGRHS s], LIE s, TcType s)
33 = tcGRHS grhs `thenTc` \ (grhs', lie, ty) ->
34 returnTc ([grhs'], lie, ty)
37 = tcGRHS grhs `thenTc` \ (grhs', lie1, ty1) ->
38 tcGRHSs grhss `thenTc` \ (grhss', lie2, ty2) ->
39 unifyTauTy ty1 ty2 `thenTc_`
40 returnTc (grhs' : grhss', lie1 `plusLIE` lie2, ty1)
43 tcGRHS (OtherwiseGRHS expr locn)
45 tcExpr expr `thenTc` \ (expr, lie, ty) ->
46 returnTc (OtherwiseGRHS expr locn, lie, ty)
48 tcGRHS (GRHS guard expr locn)
50 tc_stmts guard `thenTc` \ ((guard', expr', ty), lie) ->
51 returnTc (GRHS guard' expr' locn, lie, ty)
53 tc_stmts [] = tcExpr expr `thenTc` \ (expr2, expr_lie, expr_ty) ->
54 returnTc (([], expr2, expr_ty), expr_lie)
55 tc_stmts (stmt:stmts) = tcStmt tcExpr ListComp (\x->x) combine stmt $
58 combine stmt _ (stmts, expr, ty) = (stmt:stmts, expr, ty)
62 @tcGRHSsAndBinds@ typechecks (grhss where binds), returning suitable
66 tcGRHSsAndBinds :: RenamedGRHSsAndBinds
67 -> TcM s (TcGRHSsAndBinds s, LIE s, TcType s)
69 tcGRHSsAndBinds (GRHSsAndBindsIn grhss binds)
72 (tcGRHSs grhss `thenTc` \ (grhss', lie, ty) ->
73 returnTc (GRHSsAndBindsOut grhss' EmptyBinds ty, lie)
74 ) `thenTc` \ (grhss_and_binds'@(GRHSsAndBindsOut _ _ result_ty), lie) ->
75 returnTc (grhss_and_binds', lie, result_ty)
77 combiner binds1 (GRHSsAndBindsOut grhss binds2 ty)
78 = GRHSsAndBindsOut grhss (binds1 `ThenBinds` binds2) ty