
On Sat, Sep 08, 2007 at 09:03:45PM -0700, Bryan O'Sullivan wrote:
I would prefer to see the API changed to associate the type of a value with the name of its constructor, like this:
data SocketOption = DontRoute Bool | TimeToLive Int64 | ...
One could still pass values of this type into getSocketOption by filling out the arguments to a constructor with any value, including undefined. There's already ample precedent for this, in the form of Data.Storable's sizeOf.
This presents a safer statically checkable interface, while remaining in the bounds of H98.
I thought of this, but didn't go this way because I did not want to change the existing SocketOption type. There's also some argument that providing such a type is higher-level than the Network.Socket library, since everything else is pretty much as unforgiving as C. The point of this patch was to bring the Haskell API to getsockopt/setsockopt at least to the level of the C API (which exploits weak typing). I would much prefer a nicer interface, of course, but I am not sure that it should be part of Network.Socket. I was originally planning to write something with type families, but then realized that this had to run in Hugs as well. -- -- Matthew Danish -- user: mrd domain: cmu.edu -- OpenPGP public key: C24B6010 on keyring.debian.org