Custom instances of HStream impossible to write
- Ngôn ngữ chính
- Haskell
- Star
- 186
- Fork
- 59
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
It would be nice to be able to have an instance of [`HStream`](http://hackage.haskell.org/package/HTTP-4000.2.19/docs/Network-TCP.html#t: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
``` haskell
openStream :: String -> Int -> IO (HandleStream bufType)
close :: HandleStream bufType -> IO ()
```
For the implementation of `openStream` we can use
``` haskell
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
``` haskell
hstreamToConnection :: HandleStream String -> Connection
```
and there is a [`Stream`](http://hackage.haskell.org/package/HTTP-4000.2.19/docs/Network-Stream.html#t:Stream) instance for [`Connection`](http://hackage.haskell.org/package/HTTP-4000.2.19/docs/Network-TCP.html#t:Connection), `hstreamToConnection` works _only_ for `HandleStream String`, so that doesn't help either.
Finally, the [`HandleStream`](http://hackage.haskell.org/package/HTTP-4000.2.19/docs/Network-TCP.html#t: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.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Bắt đầu với HStream, HandleStream, openStream, close và openTCPConnection trong Network.TCP, sau đó kiểm tra hstreamToConnection và Connection trong Network.Stream. Xác định một API cho phép các instance HStream tùy chỉnh đóng HandleStream của chúng mà không cần lazy I/O hoặc phụ thuộc vào chuyển đổi dành riêng cho String. Hoàn thành khi một kiểu bộ đệm tùy chỉnh có thể định nghĩa việc dọn dẹp kết nối một cách tường minh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- haskell
- Lĩnh vực
- networking
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100