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

Custom instances of HStream impossible to write #86

Open
edsko opened this issue May 22, 2015 · 0 comments
Open

Custom instances of HStream impossible to write #86

edsko opened this issue May 22, 2015 · 0 comments

Comments

@edsko
Copy link

edsko commented May 22, 2015

It would be nice to be able to have an instance of HStream that allows to stream without using lazy I/O; in particular, an instance that would allow us to close the connection when we no longer want the rest of the response body.

However, in order to define a custom type with a corresponding HStream instance one needs to provide, amongst other things, implementations of

openStream :: String -> Int -> IO (HandleStream bufType)
close :: HandleStream bufType -> IO ()

For the implementation of openStream we can use

openTCPConnection :: BufferType ty => String -> Int -> IO (HandleStream ty)

However, for the implementation of close we are stuck; there is no function analogous to openTCPConnection that allows us to close a HandleStream.

Although we have

hstreamToConnection :: HandleStream String -> Connection

and there is a Stream instance for Connection, hstreamToConnection works only for HandleStream String, so that doesn't help either.

Finally, the HandleStream type is completely opaque (it does not even satisfy Functor) so we cannot define a HStream instance for one bufType in terms of the HStream instance for another. If we had some way of defining new instances in terms of old instances (for instance, reuse the instance for lazy bytestrings, but somehow retain a handle to the corresponding HandleStream so that we can close it explicitly) that would be great.

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

1 participant