[Haskell-beginners] Network PortNumber deprecation warning

Jeff C. Britton jcb at iteris.com
Fri Aug 16 22:13:38 UTC 2019


The Network module is deprecated.  I didn’t really get that from the warning, I thought it was just about PortNumber.
From Hackage:
“””
Milestones
2.7
See https://github.com/haskell/network/issues/296
• [x] Making Network deprecated
• [x] Making Network.BSD deprecated
• [x] Making MkSocket deprecated
 “””
----

From: Beginners [mailto:beginners-bounces at haskell.org] On Behalf Of Theodore Lief Gannon
Sent: Friday, August 16, 2019 10:23 AM
To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners at haskell.org>
Subject: Re: [Haskell-beginners] Network PortNumber deprecation warning

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 <mailto: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
mailto:Beginners at haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
ATTENTION: This email is from an external source. Always use caution when opening attachments or clicking links from unknown senders or when receiving unexpected emails. 


More information about the Beginners mailing list