<p dir="ltr">I want to write a function that will read the contents of a file and return a Vector of its lines:</p>
<p dir="ltr">readLines :: Handle -> IO (Vector String)</p>
<p dir="ltr">I have an implementation that works but seems to naive and inefficient to me because it reads the entire file contents, <i>then </i>splits it into lines, and <i>then</i> converts it to a Vector from a list. </p>
<p dir="ltr">readLines h = fromList . lines <$> hGetContents h</p>
<p dir="ltr">I would like to a) use hGetLine and continue until I get an isEOFError and b) read directly into a Vector instead of a list. I started something using Data.Vector.unfoldr but I the presence of the IO monad around my String was causing issues I couldn't figure out how to solve. </p>
<p dir="ltr">I'd also be curious to see how to do either one of these things separately and I assume they'd each help make my program more efficient on their own. Or, maybe my implementation is not as terrible as I thought because some laziness/fusion/optimization magic is happening behind the scenes? </p>
<p dir="ltr">Thanks,<br>
Jake Waksbaum</p>