<div dir="ltr">Those System.IO functions *are* String-specific. Try the equivalents from Data.ByteString:<div><br></div><div><a href="http://hackage.haskell.org/package/bytestring-0.10.8.1/docs/Data-ByteString.html#g:29">http://hackage.haskell.org/package/bytestring-0.10.8.1/docs/Data-ByteString.html#g:29</a><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 10, 2017 at 2:46 PM, Manuel Vázquez Acosta <span dir="ltr"><<a href="mailto:mva.led@gmail.com" target="_blank">mva.led@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I'm quite new to Haskell.  While following the "Real World Haskell" and<br>
doing some experimentation I came up with a anoying situation:<br>
<br>
Trying to read data from stdin it seems that binary data is not<br>
allowed.  A simple "copy" program:<br>
<br>
<br>
   -- file: copy.hs<br>
   import System.IO<br>
<br>
   main = do<br>
      input <- hGetContents stdin<br>
      hPutStr input<br>
<br>
Fails when I run it like:<br>
<br>
   $ ghc copy.hs<br>
   $ ./copy < input > output<br>
   copy: <stdin>: hGetContents: invalid argument (invalid byte sequence)<br>
<br>
input contains binary data.  In fact of all the following programs only<br>
the first works with binary data:<br>
<br>
  copy:: IO ()<br>
  copy = do<br>
    bracket (openBinaryFile "input" ReadMode) hClose $ \hi -> do<br>
      bracket (openBinaryFile "ouput" WriteMode) hClose $ \ho -> do<br>
        input <- hGetContents hi<br>
        hPutStr ho input<br>
<br>
<br>
  copy2:: IO ()<br>
  copy2 = do<br>
    -- Doesn't work with binary files<br>
    source <- readFile "input"<br>
    writeFile "output" source<br>
<br>
<br>
  copy3:: IO ()<br>
  copy3 = do<br>
    -- Doesn't work with binary files either<br>
    interact (map $ \x -> x)<br>
<br>
<br>
  copy4:: IO ()<br>
  copy4 = do<br>
    input <- hGetContents stdin<br>
    hPutStr stdout input<br>
<br>
<br>
But I lost any chance of piping and/or using '<', '>' in the shell.<br>
<br>
Best regards,<br>
Manuel.<br>
______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>