[RFC] Network.Socket: change get/setSocketOption

Simon Marlow simonmarhaskell at gmail.com
Fri Jul 14 05:45:13 EDT 2006

Bertram Felgenhauer wrote:

> (This mail is related to
>   http://permalink.gmane.org/gmane.comp.lang.haskell.libraries/3788 )
> 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 ()
> To make that work, the two functions are implemented in a type class.

I think this is a reasonable design, despite the slight misuse of algebraic data 
types.  I thought about using a type class with a functional dependency to 
express the relationship between the option tag and the option type, but that 
ends up being more elaborate for not much gain.

Simon PJ pointed out to me an alternative design using GADTs:

data SocketOption a where
   ReuseAddr :: SocketOption Int

getSocketOption :: Socket -> SocketOption a -> IO a
setSocketOption :: Socket -> SocketOption a -> a -> IO ()

This seems to me the best design, but requiring GADTs isn't really practical for 
this widely-used API.

So I'm in favour of Bertram's proposal above... any other comments?


More information about the Libraries mailing list