Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hGet documentation on return type is incorrect #588

Open
robinp opened this issue May 25, 2023 · 1 comment
Open

hGet documentation on return type is incorrect #588

robinp opened this issue May 25, 2023 · 1 comment

Comments

@robinp
Copy link

robinp commented May 25, 2023

Hello,

See

hGet :: Handle -> Int -> IO ByteString
. It states it returns the bytes read, up to n. But that is the behavior of the underlying hGetBuf, not hGet. hGet itself returns a ByteString with length up to n.

I think it would also be ergonomic to call out with emphasis that near EOF the returned bytestring can be shorter. (On a quick skimming, I assumed that hGet would fail / return empty if not enough bytes are available, while hGetSome would return the partial bytes. But turns out the difference is rather in terms of blocking or not in case data is not yet available?)

Also the doc Like hGet, except that a shorter ByteStringmay be returned if there are not enough bytes immediately available to satisfy the whole request. on hGetSome adds to the confusion. Kind of implies to the unaware reader that hGet would always return non-shorter bytestring.

@Bodigrim
Copy link
Contributor

But turns out the difference is rather in terms of blocking or not in case data is not yet available?

Correct. It all follows the behaviour of https://hackage.haskell.org/package/base-4.18.0.0/docs/System-IO.html#v:hGetBuf and below.

Feel free to raise a PR improving documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants