'How to bind socket to localhost in Standard ML
How do I bind an inet socket to localhost (127.0.0.1) in Standard ML? I came up with Socket.bind (socket, INetSock.toAddr (valOf (NetHostDB.fromString "127.0.0.1"), portNumber)), but this seems awfully verbose. I think there might exist a simpler way. Is there a simpler way?
For context, this is the program:
fun startServer () =
  let
    val socket = INetSock.TCP.socket ()
    val localhost = valOf (NetHostDB.fromString "127.0.0.1")
  in
    Socket.bind (socket, INetSock.toAddr (localhost, 8000));
    Socket.listen (socket, 10);
    (* ... do some things with the socket ... *)
  end
							
						Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|
