+ expr (of IO type) ==> expr >>= \ v -> return [v]
+ [NB: result not printed] bindings: [it]
+
+
+ expr (of non-IO type,
+ result showable) ==> let v = expr in print v >> return [v]
+ bindings: [it]
+
+ expr (of non-IO type,
+ result not showable) ==> error
+
+\begin{code}
+#ifdef GHCI
+hscStmt -- Compile a stmt all the way to an HValue, but don't run it
+ :: HscEnv
+ -> PersistentCompilerState -- IN: persistent compiler state
+ -> InteractiveContext -- Context for compiling
+ -> String -- The statement
+ -> IO ( PersistentCompilerState,
+ Maybe (InteractiveContext, [Name], HValue) )
+
+hscStmt hsc_env pcs icontext stmt
+ = do { maybe_stmt <- hscParseStmt (hsc_dflags hsc_env) stmt
+ ; case maybe_stmt of {
+ Nothing -> return (pcs, Nothing) ;
+ Just parsed_stmt -> do {
+
+ -- Rename and typecheck it
+ (pcs1, maybe_tc_result)
+ <- tcRnStmt hsc_env pcs icontext parsed_stmt
+
+ ; case maybe_tc_result of {
+ Nothing -> return (pcs1, Nothing) ;
+ Just (new_ic, bound_names, tc_expr) -> do {
+
+ -- Then desugar, code gen, and link it
+ ; hval <- compileExpr hsc_env pcs1 iNTERACTIVE
+ (ic_rn_gbl_env new_ic)
+ (ic_type_env new_ic)
+ tc_expr
+
+ ; return (pcs1, Just (new_ic, bound_names, hval))
+ }}}}}
+
+hscTcExpr -- Typecheck an expression (but don't run it)
+ :: HscEnv
+ -> PersistentCompilerState -- IN: persistent compiler state
+ -> InteractiveContext -- Context for compiling
+ -> String -- The expression
+ -> IO (PersistentCompilerState, Maybe Type)
+
+hscTcExpr hsc_env pcs icontext expr
+ = do { maybe_stmt <- hscParseStmt (hsc_dflags hsc_env) expr
+ ; case maybe_stmt of {
+ Just (ExprStmt expr _ _)
+ -> tcRnExpr hsc_env pcs icontext expr ;
+ Just other -> do { hPutStrLn stderr ("not an expression: `" ++ expr ++ "'") ;
+ return (pcs, Nothing) } ;
+ Nothing -> return (pcs, Nothing) } }