ben131
1
I have a type that represents a simple TCP client like the one below:
type t = {
flow: _ Eio.Flow.two_way; (* This is not work, and I need the return type of Eio.Net.connect here, what should it be? *)
...
}
By the way, I find types like the below in Eio difficult to understand. What material do I need to study to understand them?
type 'a stream_socket = 'a Std.r constraint 'a = [> [> `Generic ] stream_socket_ty ]
talex5
2
The Casting section of the README might help.
The type says that an 'a stream_socket
is a resource with features 'a
, which must include at least the features in stream_socket_ty
:
type 'tag stream_socket_ty = [
| `Stream
| `Platform of 'tag
| `Shutdown
| socket_ty
| Flow.source_ty
| Flow.sink_ty
]
So you can use a stream socket as a flow source or sink, call shutdown on it, etc.
1 Like
ben131
3
Thanks! This solved my problem.
Just out of curiosity, why use these polymorphic variant types(I am not familiar with them) instead of object types in the Eio’s APIs?
talex5
4
Just out of curiosity, why use these polymorphic variant types(I am not familiar with them) instead of object types in the Eio’s APIs?
Some people strongly dislike objects (polymorphic records) but are OK with polymorphic variants.