Error in enumerator when using interpreter instead of compiler

Hi all, I was trying out the enumerator package. I wanted to copy the contents of one file to another: module Main where import Data.Enumerator import Data.Enumerator.IO main = run (enumFile "foo" $$ iterFile "bar") If I compile this code with GHC, it works as expected. But if I run it with runhaskell I get the following error: Left bar: hPutBuf: illegal operation (handle is closed) If I replace the above code with this: module Main where import Data.Enumerator import Data.Enumerator.IO import System.IO main = withBinaryFile "bar" WriteMode $ \h -> run (enumFile "foo" $$ iterHandle h) It works both compiled and interpreted. Is this a bug in enumerator (probably in the iterFile function) or a deficiency of the interpreter?

I forgot to mention that the file "bar" is created but empty. So it seems the Iteratee opens it and then closes it prematurely.

It's certainly a bug in iterFile -- I think it'll have to be modified to close the file on EOF, not after returning a continuation. Semi-working in the compiled version is probably just a quirk of the garbage collector and/or OS.

Well, now I know why the "iteratee" package never defined something like "iterFile" -- it's not really possible. The only way to open handles within an iteratee prevents exception-safe release. enumerator-0.3 will remove the iterFile functions. iterHandle will remain, to be used as in your second example.
participants (2)
-
John Millikin
-
Tobias Brandt