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

Thomas DuBuisson thomas.dubuisson at gmail.com
Sun Jun 21 19:22:42 EDT 2009


I'm in favor of the entire Network library being reworked with an
improved API that is higher level and type-safe instead of a direct
translation/FFI of Berkeley sockets.   I also would like the Network
package to export Data instances for headers while taking advantage of
pretty, prettyclass, and parsec.  I started such work with
network-data but never really got off the ground with it.

Thomas

On Sun, Jun 21, 2009 at 2:45 PM, John Van Enk<vanenkj at gmail.com> wrote:
> 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
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list