Hello,
this happens because "head" probably closes the file descriptor after 3 lines, and then the Haskell program tries to write to a closed handle (i.e., it's stdout is not there anymore).  The best thing to do depends on the program. One fairly simple option would be to handle the exception, and do something (perhaps ignore it).
-Iavor

On Mon, Aug 27, 2012 at 10:55 AM, Eric Tanter <etanter@dcc.uchile.cl> wrote:
Hi,

Here is a simple shell script (upper.hs):

import Data.Char
main = interact $ map toUpper

which composes fine with other scripts:

bash-3.2$ yes | head -n 3 | runghc upper.hs
Y
Y
Y

but not always:

bash-3.2$ yes | runghc upper.hs | head -n 3
Y
Y
Y
<stdout>: hFlush: resource vanished (Broken pipe)

Any idea why this error occurs/how to avoid it?

(running just:
yes | runghc upper.hs
gives the expected infinite stream of Ys)

Thanks!

-- Éric

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe