304 | | e = f 10 |

305 | | |

306 | | f :: Int -> [Int] -> Int |

307 | | f = \x -> case fac x < 10 of |

308 | | True -> \_ -> 3 |

309 | | False -> hd |

310 | | |

311 | | hd :: [a] -> a |

312 | | hd = \x -> case x of |

313 | | [] -> error "hd: empty list" |

314 | | (x:_) -> x |

315 | | |

316 | | fac :: Int -> Int |

317 | | fac = \n -> case n == 0 of |

318 | | True -> 1 |

319 | | False -> n * fac (n - 1) |

320 | | }}} |

321 | | |

| 304 | e = f ["e"] 10 |

| 305 | |

| 306 | f :: Trace -> Int -> [Int] -> Int |

| 307 | f = \t x -> case fac ("f":t) x < 10 of |

| 308 | True -> \_ -> 3 |

| 309 | False -> hd ("f":t) |

| 310 | |

| 311 | hd :: Trace -> [a] -> a |

| 312 | hd = \t x -> case x of |

| 313 | [] -> error ("hd: empty list " ++ show t) {- simple hack so we can see the stack -} |

| 314 | (x:_) -> x |

| 315 | |

| 316 | fac :: Trace -> Int -> Int |

| 317 | fac = \t n -> case n == 0 of |

| 318 | True -> 1 |

| 319 | False -> n * fac ("fac":t) (n - 1) {- no stack pruning, though there ought to be -} |

| 320 | }}} |

| 321 | |

| 322 | When you fun this program you get: |

| 323 | {{{ |

| 324 | Program error: hd: empty list ["f","e"] |

| 325 | }}} |

| 326 | Which is essentially: |

| 327 | {{{ |

| 328 | e -> f -> hd |

| 329 | }}} |

| 330 | ''Note'': this is different to the stack trace given by hat-stack above. |