Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Custom instances of HStream impossible to write

Open
#86 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
haskell
Domain
networking

Research direction

Start with HStream, HandleStream, openStream, close, and openTCPConnection in Network.TCP, then inspect hstreamToConnection and Connection in Network.Stream. Determine an API that lets custom HStream instances close their HandleStream without lazy I/O or relying on the String-specific conversion. Done means a custom buffer type can define explicit connection cleanup.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Haskell
Stars
186
Forks
59
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from haskell/HTTP

All issues in haskell/HTTP

Similar issues

More Haskell issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.