[RFC] Network.Socket: change get/setSocketOption

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Sun Jun 25 09:08:20 EDT 2006

On 6/25/06, I wrote:
> What I'm proposing is to make SocketOption a proper ADT and change
> get- and setSocketOption to functions that take type constructors
> instead of tags as arguments, i.e.
>   getSocketOption :: Socket -> (a -> SocketOption) -> IO a
>   setSocketOption :: Socket -> (a -> SocketOption) -> a -> IO ()

It should be noted that while the patch defines an ADT, it does
sort of abuse it by providing an interface that uses the constructors
in a tag-like manner. I did this for two reasons, first, it saves a
bunch of code, and second, it mimics the old interface very closely.

Passing a non-constructor argument will lead to weird results, but
as far as I can see, nothing truly bad happens, no memory corruption
at least.

I could easily be persuaded to actually make the interface look like
  getSocketOption :: Socket -> SocketOption -> IO SocketOption
  setSocketOption :: Socket -> SocketOption -> IO ()
(getSocketOption would fill in the value in SocketOption with the
actual value, that is the parameter would act as a template)

This increases safety, but it comes at a cost in code size (with
ugly #ifdefs), unless I'm missing something.

I'd like to avoid creating a second ADT for queries or separate
functions for each of the options.


More information about the Libraries mailing list