2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
4 \section[TcGRHSs]{Typecheck guarded right-hand-sides}
7 module TcGRHSs ( tcGRHSsAndBinds ) where
9 #include "HsVersions.h"
11 import HsSyn ( HsBinds(..), GRHSsAndBinds(..), GRHS(..), DoOrListComp(..) )
12 import RnHsSyn ( RenamedGRHSsAndBinds, RenamedGRHS )
13 import TcHsSyn ( TcGRHSsAndBinds, TcGRHS )
16 import Inst ( Inst, LIE, plusLIE )
17 import TcBinds ( tcBindsAndThen )
18 import TcExpr ( tcExpr, tcStmt )
19 import TcType ( TcType )
23 tcGRHSs :: TcType s -> [RenamedGRHS] -> TcM s ([TcGRHS s], LIE s)
25 tcGRHSs expected_ty [grhs]
26 = tcGRHS expected_ty grhs `thenTc` \ (grhs', lie) ->
27 returnTc ([grhs'], lie)
29 tcGRHSs expected_ty (grhs:grhss)
30 = tcGRHS expected_ty grhs `thenTc` \ (grhs', lie1) ->
31 tcGRHSs expected_ty grhss `thenTc` \ (grhss', lie2) ->
32 returnTc (grhs' : grhss', lie1 `plusLIE` lie2)
34 tcGRHS expected_ty (GRHS guard expr locn)
36 tcStmts guard `thenTc` \ ((guard', expr'), lie) ->
37 returnTc (GRHS guard' expr' locn, lie)
39 tcStmts [] = tcExpr expr expected_ty `thenTc` \ (expr2, expr_lie) ->
40 returnTc (([], expr2), expr_lie)
41 tcStmts (stmt:stmts) = tcStmt tcExpr Guard (\x->x) combine stmt $
44 combine stmt _ (stmts, expr) = (stmt:stmts, expr)
48 @tcGRHSsAndBinds@ typechecks (grhss where binds), returning suitable
52 tcGRHSsAndBinds :: TcType s -- Expected type of RHSs
53 -> RenamedGRHSsAndBinds
54 -> TcM s (TcGRHSsAndBinds s, LIE s)
56 -- Shortcut for common case
57 tcGRHSsAndBinds expected_ty (GRHSsAndBindsIn grhss EmptyBinds)
58 = tcGRHSs expected_ty grhss `thenTc` \ (grhss', lie) ->
59 returnTc (GRHSsAndBindsOut grhss' EmptyBinds expected_ty, lie)
61 tcGRHSsAndBinds expected_ty (GRHSsAndBindsIn grhss binds)
64 (tcGRHSs expected_ty grhss)
66 combiner is_rec binds grhss
67 = GRHSsAndBindsOut grhss (MonoBind binds [] is_rec) expected_ty