
John Goerzen wrote:
On Thu, Jan 08, 2009 at 10:37:55PM +0100, Bardur Arantsson wrote:
Don't get me wrong -- the socket support is pretty decent, but there are also some weird idiosyncrasies, for example requiring that the PortNum is specified in network byte order and lacking a function to convert host->network byte order (hton).
Look at Haddock for PortNumber:
newtype PortNumber Constructors PortNum Word16
Instances
Enum PortNumber Eq PortNumber Integral PortNumber Num PortNumber Ord PortNumber Real PortNumber Show PortNumber Typeable PortNumber Storable PortNumber
Try it in ghci:
Prelude Network.Socket> 15 :: PortNumber 15 Prelude Network.Socket> PortNum 15 3840 Prelude Network.Socket> (fromIntegral (15::Int))::PortNumber 15
So, in essence, there are *many* functions that let you do this. You should not be needing to construct PortNum by hand.
Thanks. For some reason I hadn't thought to use (fromIntegral x)::PortNumber I guess I got stuck on the idea of constructing a PortNum directly and didn't think beyond that. (Maybe PortNum should really be an abstract type to force indirect construction...?) I guess the API isn't all that idiosyncratic after all :). Cheers, Bardur Arantsson