I Hate IO

Simon Marlow simonmar@microsoft.com
Mon, 13 Aug 2001 12:33:01 +0100


> I can only tell you what's useful for me as an API user.=20
> Since there are=20
> peculiar little differences between different kinds of=20
> sockets, my ideal=20
> would be every type of socket to have its own API functions, and then=20
> common patterns brought together with classes.

Ok, so the main alternatives are between
=20
  - One API with a superset of the operations available on
    Handles.  Some operations fail for some kinds of Handles.

  - A separate type and API for each kind of handle, defining
    only the operations available on that handle.  Operations
    which several types of handle share are unified using classes.

I agree the second option is conceptually cleaner, but I'm not sure I'm
motivated enough to change given that the impact in terms of breaking
existing code would be high.  That's my opinion - perhaps others feel
differently.  There may be some useful middle ground that doesn't
involve going the whole way, such as just separating streams and files.

> >Why isn't writeEnd the same as close?
>=20
> On a TCP connection, one can still receive data after sending=20
> an end. My=20
> "close" is intended to be the last thing done with the=20
> connection as an=20
> object destructor: if called before sending and receiving=20
> end, it would=20
> simply forcibly close the connection.

At least the current API should have a way of doing this - it only has
SocketPrim.shutdown which you can't use on a Handle.

> >Is there anything that is always a Source but not a Sink (or vice
> >versa)?=20
>=20
> Oh yes, lots of things. Standard input/output/error for instance. One=20
> might write code that did something like pipe from a Source=20
> to a Sink,=20
> and then one might want a Source constructed from a constant=20
> array. Or=20
> something. Stream-based encoding algorithms such as UTF-8=20
> might make use=20
> of them:
>=20
> encodeUTF8:: SourceChar -> SourceWord8

Yes, I can see that being able to plug together arbitrary sources and
sinks could be useful.  You don't have to separate sources and sinks to
do this though - if Handle were a class, then you could define new
instances for a constant array Handle, or an encoding layer on top of a
raw Handle.

Cheers,
	Simon