Difference between revisions of "Talk:Library/Streams"

From HaskellWiki
Jump to navigation Jump to search
(Notes about using the library, particularly, stdin and stdout.)
 
(Answer about stdin/stdout)
 
(One intermediate revision by one other user not shown)
Line 2: Line 2:
   
 
- bufferBlockStream
 
- bufferBlockStream
  +
 
- withEncoding utf8
 
- withEncoding utf8
  +
 
- withLocking
 
- withLocking
   
Line 16: Line 18:
   
 
Maybe this can be improved somehow in the library, but otherwise I believe it should be documented.
 
Maybe this can be improved somehow in the library, but otherwise I believe it should be documented.
  +
  +
  +
I've moved this into main documentation. It is because fdStdIn/fdStdOut provides raw file descriptors, just numbers 0 and 1. So, too use buffered String I/O on them you should apply buffering transformer. Your error was not intercepted at compile time due to weak class design where any stream implements the same Stream class and illegal operations captured only at run-time. It is fixed in 0.2 version, together with providing higher-level stdin/stdout streams with buffering transformer already applied. [[User:Bulatz|Bulatz]] 20:19, 13 November 2006 (UTC)

Latest revision as of 20:19, 13 November 2006

To be able to read and write to a file with functions such as vGetContents and vPutStrLn I think it is mandatory to define some of

- bufferBlockStream

- withEncoding utf8

- withLocking

I am sure the first one is needed, I thought the other two wasn't but then I had trouble without them. The trouble is shown as a ugly message and abortion of the program at run-time:

 *** Exception: illegal operation

I had to even add those layers to standard input and standard output, without them it was impossible to print and read. I ended up with something like:

inStream  <- bufferBlockStream fdStdIn  >>= withEncoding utf8 >>= withLocking

outStream <- bufferBlockStream fdStdOut >>= withEncoding utf8 >>= withLocking

Maybe this can be improved somehow in the library, but otherwise I believe it should be documented.


I've moved this into main documentation. It is because fdStdIn/fdStdOut provides raw file descriptors, just numbers 0 and 1. So, too use buffered String I/O on them you should apply buffering transformer. Your error was not intercepted at compile time due to weak class design where any stream implements the same Stream class and illegal operations captured only at run-time. It is fixed in 0.2 version, together with providing higher-level stdin/stdout streams with buffering transformer already applied. Bulatz 20:19, 13 November 2006 (UTC)