Hello,
I am new to ml and have downloaded poly/ML. I wanted to experiment with the socket structures. Does naybody know where I can get information on useing poly/ML with sockets.
I tried to use the INetSock.TCP.socket () function like so
vat s = INetSock.TCP.socket ();
I get a message saying that s has uninstantiated variables or something in that range. (I do not remember the correct response right now).
My question is this. Can I get an inet socket by calling INetSock.TCP.socket () function?
Regards, Riza Dindir rdindir@yahoo.com
__________________________________ Do you Yahoo!? Yahoo! Domains Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer
On Thursday, May 20, 2004, at 21:57 Europe/London, Riza Dindir wrote:
I am new to ml and have downloaded poly/ML. I wanted to experiment with the socket structures. Does naybody know where I can get information on useing poly/ML with sockets.
I tried to use the INetSock.TCP.socket () function like so
vat s = INetSock.TCP.socket ();
I get a message saying that s has uninstantiated variables or something in that range. (I do not remember the correct response right now).
My question is this. Can I get an inet socket by calling INetSock.TCP.socket () function?
Regards, Riza Dindir rdindir@yahoo.com
Hi Riza, Yes, you can create an inet socket by calling INetSock.TCP.socket. The only difficulty is that you have fallen foul of one of Standard ML's rather more arcane type checking rules.
I wrote the following function which creates a socket, looks up a host name and the "daytime" service and gets the current date from the service. (If you put this into Poly/ML you will get a couple of warnings because I haven't handled the cases where the host and/or service names can't be found, but you can ignore this).
fun getDate host = let val x = INetSock.TCP.socket() val SOME h = NetHostDB.getByName host; val hostAddr = NetHostDB.addr h; val SOME p = NetServDB.getByName("daytime", NONE); val daytime = NetServDB.port p; val _ = Socket.connect(x, INetSock.toAddr(hostAddr, daytime)); val result = Byte.bytesToString (Socket.recvVec(x, 100)); val _ = Socket.close x in result end;
If you simply type val x = INetSock.TCP.socket(); at the top level you will get an error message. You need to constrain it to a monotype by adding a type constraint e.g. val x = INetSock.TCP.socket(): Socket.active INetSock.stream_sock;
Explaining why you need the type constraint would take far too long. I suggest you find a book on ML (e.g. Larry Paulson's "ML for the Working Programmer").
Regards, David.
vat s = INetSock.TCP.socket ();
^ maybe this should be val, not vat. :D
I get a message saying that s has uninstantiated variables or something in that range. (I do not remember the correct response right now).
My question is this. Can I get an inet socket by calling INetSock.TCP.socket () function?
Regards, Riza Dindir rdindir@yahoo.com
__________________________________ Do you Yahoo!? Yahoo! Domains Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer _______________________________________________ polyml mailing list polyml@inf.ed.ac.uk http://lists.inf.ed.ac.uk/mailman/listinfo/polyml