haskell / haskell/haskell-mode

Forked thread stops printing to stdout in haskell-interactive-mode.

Open
#1,430 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Emacs Lisp
Stars
1.4k
Forks
354
Avg merge
5d 10h
Merged PRs (30d)
2

Description

Running a separate thread, which prints to stdout or stderr, works as expected directly in GHCI and in `inf-haskell`, but in `haskell-interactive-mode` it simply stops writing to `stdout` whenever nothing is waiting for it. Here is an example of the issue:

```
foo :: Int -> IO ()
foo 0 = return ()
foo n = do
putStrLn $ "Counting: " ++ show n
hFlush stdout -- just in case.
threadDelay 1000000
foo (n-1)

bar :: IO (IO ())
bar = async (foo 10) >>= (return . wait)
```

So, if I call `bar`, it just stops counting after the first iteration:

```
λ> g <- bar
Counting: 10
λ>
```

But if I start waiting for that thread a few seconds later it resumes printing to `stdout`.

```
λ> g
Counting: 6
Counting: 5
Counting: 4
Counting: 3
Counting: 2
Counting: 1
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the example in haskell-interactive-mode and compare its behavior with GHCI and inf-haskell. Trace how the mode handles stdout and stderr while the prompt is idle; done means a forked thread continues printing without waiting for its result.

Written by the indexing model from the issue text.

Assessment

Tech stack
emacs, haskell
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.