| 1 | module Q (tcExtendIdEnv2) where |
|---|
| 2 | |
|---|
| 3 | -- Interesting code: |
|---|
| 4 | |
|---|
| 5 | tcExtendIdEnv2 :: M a |
|---|
| 6 | tcExtendIdEnv2 = do env <- getEnv |
|---|
| 7 | let level :: Int |
|---|
| 8 | level = thLevel (tcl_th_ctxt env) |
|---|
| 9 | level `seq` tc_extend_local_id_env level |
|---|
| 10 | |
|---|
| 11 | {-# NOINLINE tc_extend_local_id_env #-} |
|---|
| 12 | tc_extend_local_id_env :: Int -> M a |
|---|
| 13 | tc_extend_local_id_env th_lvl = if read "foo" |
|---|
| 14 | then th_lvl `seq` return undefined |
|---|
| 15 | else return undefined |
|---|
| 16 | |
|---|
| 17 | thLevel :: ThStage -> Int |
|---|
| 18 | thLevel Comp = 0 |
|---|
| 19 | thLevel (Splice l) = l |
|---|
| 20 | thLevel (Brack l) = l |
|---|
| 21 | |
|---|
| 22 | -- Dull code: |
|---|
| 23 | |
|---|
| 24 | type M a = IOEnv TcLclEnv a |
|---|
| 25 | |
|---|
| 26 | data TcLclEnv = TcLclEnv { tcl_th_ctxt :: !ThStage } |
|---|
| 27 | |
|---|
| 28 | data ThStage = Comp | Splice Int | Brack Int |
|---|
| 29 | |
|---|
| 30 | getEnv :: IOEnv env env |
|---|
| 31 | getEnv = IOEnv (\ env -> return env) |
|---|
| 32 | |
|---|
| 33 | newtype IOEnv env a = IOEnv { unIOEnv :: env -> IO a } |
|---|
| 34 | |
|---|
| 35 | instance Monad (IOEnv m) where |
|---|
| 36 | IOEnv m >>= f = IOEnv (\ env -> do r <- m env |
|---|
| 37 | unIOEnv (f r) env ) |
|---|
| 38 | return a = IOEnv (\ _ -> return a) |
|---|
| 39 | fail = error |
|---|