[Haskell-cafe] Suggestion for Network.Socket in regards to PortNumber

John Van Enk vanenkj at gmail.com
Sun Jun 21 17:45:04 EDT 2009


Hello List,

Is there any one else in favor of hiding the PortNum constructor in
Network.Socket in the next release? Here's why:

Prelude> :m + Network.Socket Data.Word
Prelude Network.Socket Data.Word> let p = 5000 :: Word16
Prelude Network.Socket Data.Word> let p' = PortNum p
Prelude Network.Socket Data.Word> let p'' = fromIntegral p :: PortNumber
Loading package parsec-2.1.0.1 ... linking ... done.
Loading package network-2.2.1.1 ... linking ... done.
Prelude Network.Socket Data.Word> p
5000
Prelude Network.Socket Data.Word> p'
34835
Prelude Network.Socket Data.Word> p''
5000

Notice that using the PortNum constructor does not at all do what the
user expects. This really should be a hidden constructor.

Perhaps we can add the following:

mkPortNum :: (Num a) => a -> PortNumber
mkPortNum p = fromIntegral p

/jve


More information about the Haskell-Cafe mailing list