|
|
|
|
|
by mrkeen
720 days ago
|
|
Before I was good at Haskell, I would approach a data-processing job sequentially based on the next thing that needs to be done. I want to open a file, and I can't read it all at once, so I'll use a FileReader and it should be buffered, so I'll wrap it with a BufferedReader. I'll use try-with-resources and click into the classes because I can't remember if the contract of the outermost reader is that it will close the inner readers too. Right, now I'll grab the next n bytes from the stream, and start thinking about the algorithm. Swear a bit when I think about crossing the buffer boundaries, and on-and-on... The IO concerns are very much interwoven with the algorithm. In Haskell I just start by writing one function from bytes to bytes. That's the computation. Then when that's done I expose that function as bytes to bytes. Others can hook it up to files, webservers, pipe it through gzip, whatever! |
|