[Haskell-beginners] Network PortNumber deprecation warning

Jeff C. Britton jcb at iteris.com
Wed Aug 14 17:59:14 UTC 2019


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)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20190814/dccc0b89/attachment.html>


More information about the Beginners mailing list