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 #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ <= 201
13 IMPORT_DELOOPER(TcLoop) -- for paranoia checking
16 import HsSyn ( GRHSsAndBinds(..), GRHS(..), MonoBinds, Stmt, DoOrListComp(..),
17 HsExpr, HsBinds(..), InPat, OutPat, Sig, Fake )
18 import RnHsSyn ( SYN_IE(RenamedGRHSsAndBinds), SYN_IE(RenamedGRHS) )
19 import TcHsSyn ( SYN_IE(TcGRHSsAndBinds), SYN_IE(TcGRHS) )
22 import Inst ( Inst, SYN_IE(LIE), plusLIE )
23 import Kind ( mkTypeKind )
24 import TcBinds ( tcBindsAndThen )
25 import TcExpr ( tcExpr, tcStmt )
26 import TcType ( SYN_IE(TcType), TcIdOcc(..), newTyVarTy )
28 import TysWiredIn ( boolTy )
32 tcGRHSs :: TcType s -> [RenamedGRHS] -> TcM s ([TcGRHS s], LIE s)
34 tcGRHSs expected_ty [grhs]
35 = tcGRHS expected_ty grhs `thenTc` \ (grhs', lie) ->
36 returnTc ([grhs'], lie)
38 tcGRHSs expected_ty (grhs:grhss)
39 = tcGRHS expected_ty grhs `thenTc` \ (grhs', lie1) ->
40 tcGRHSs expected_ty grhss `thenTc` \ (grhss', lie2) ->
41 returnTc (grhs' : grhss', lie1 `plusLIE` lie2)
44 tcGRHS expected_ty (OtherwiseGRHS expr locn)
46 tcExpr expr expected_ty `thenTc` \ (expr, lie) ->
47 returnTc (OtherwiseGRHS expr locn, lie)
49 tcGRHS expected_ty (GRHS guard expr locn)
51 tc_stmts guard `thenTc` \ ((guard', expr'), lie) ->
52 returnTc (GRHS guard' expr' locn, lie)
54 tc_stmts [] = tcExpr expr expected_ty `thenTc` \ (expr2, expr_lie) ->
55 returnTc (([], expr2), expr_lie)
56 tc_stmts (stmt:stmts) = tcStmt tcExpr ListComp (\x->x) combine stmt $
59 combine stmt _ (stmts, expr) = (stmt:stmts, expr)
63 @tcGRHSsAndBinds@ typechecks (grhss where binds), returning suitable
67 tcGRHSsAndBinds :: TcType s -- Expected type of RHSs
68 -> RenamedGRHSsAndBinds
69 -> TcM s (TcGRHSsAndBinds s, LIE s)
71 tcGRHSsAndBinds expected_ty (GRHSsAndBindsIn grhss binds)
74 (tcGRHSs expected_ty grhss `thenTc` \ (grhss', lie) ->
75 returnTc (GRHSsAndBindsOut grhss' EmptyBinds expected_ty, lie)
78 combiner is_rec binds1 (GRHSsAndBindsOut grhss binds2 ty)
79 = GRHSsAndBindsOut grhss ((MonoBind binds1 [] is_rec) `ThenBinds` binds2) ty