3 ms·
It is a cost because you now have to carry around your static function with you wherever you code. Either you 1. have it in a utils library that adds to the ex
by zaphar 17y ago
It is a cost because you now have to carry around your static function with you wherever you code.
Either you 1. have it in a utils library that adds to the external dependencies of all your java projects. or 2. you copy and paste it everywhere.
Either way it's a cost however small that java has and other languages have.
Additionally your example doesn't really demonstrate the same feature the haskell example did, which was a stream that haskell through laziness handles transparently for you. Your readfile static function breaks the stream because it forces you to read the entire file into memory before returning the contents. That was sort of the point and your counter example in java demonstrates it beautifully.
An example that did what the haskell example did would require significantly more code.