[Haskell-beginners] Network PortNumber deprecation warning

Theodore Lief Gannon tanuki at gmail.com
Fri Aug 16 17:22:57 UTC 2019


You may have figured this out by now, but according to the docs, the error
is correct: PortNumber exposes no constructor at all. Instead, it has a Num
instance; you should be able to just use the literal 7200 there.

This strikes me as a highly questionable decision on the part of the module
authors, but it is at least convenient.

On Wed, Aug 14, 2019, 10:59 AM Jeff C. Britton <jcb at iteris.com> wrote:

> I have just installed Haskell using Stack on Windows.
>
> I wanted to try and write some code to do network programming with TCP/IP.
>
> I found a simple example on Stack Overflow to start me off.
>
> I’m having some problems with PortNumber and deprecated warnings.
>
> I don't know how to modify the code to be deprecation free.
>
>
>
> stack install network – installed version 2.8.0.1
>
>
>
> -------------------------
>
> package.yaml
>
> network >= 2.8.0.1
>
> ---------------------------
>
>
>
> The following code gives a deprecation warning, but ultimately my sample
> compiles and runs.
>
>
>
> import qualified Network
>
> import qualified Network.Socket
>
>
>
> main = Network.withSocketsDo $ do
>
>   handle <- Network.connectTo "192.168.1.2" (Network.PortNumber 7200)
>
>   talk handle `finally` hClose handle
>
>
>
> D:\work\hsSocket\app\Main.hs:14:46: warning: [-Wdeprecations]
>
>     In the use of data constructor `PortNumber'
>
>     (imported from Network):
>
>     Deprecated: "The high level Network interface is no longer supported.
> Please use Network.Socket."
>
>
>
>
>
> -----------------------------------------
>
> So, now I try and use Network.Socket as the warning indicates.
>
>
>
> main = Network.withSocketsDo $ do
>
>   handle <- Network.connectTo "192.168.1.2" (Network.Socket.PortNumber
> 7200)
>
>   talk handle `finally` hClose handle
>
>
>
> D:\work\hsSocket\app\Main.hs:15:46: error:
>
>     Not in scope: data constructor `Network.Socket.PortNumber'
>
>     Module `Network.Socket' does not export `PortNumber'.
>
>    |
>
> 15 |   handle <- Network.connectTo "192.168.1.2"
> (Network.Socket.PortNumber 7200)
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20190816/537f4d2b/attachment.html>


More information about the Beginners mailing list