Click to See Complete Forum and Search --> : O'caml help, please.


Energon
01-20-2003, 06:17 PM
I'm learning O'caml for a report at the end of the semester in my programming languages class, and I seem to have gotten myself stuck.

I'm trying to write a really simple network client app:

let sockaddr_from_host_port (host, port) =
let inetaddr =
if host = "" then
Unix.inet_addr_any
else
try
let addr = Unix.inet_addr_of_string(host) in
(Unix.gethostbyaddr addr).Unix.h_addr_list.(0)
with
Failure(i) -> (Unix.gethostbyname host).Unix.h_addr_list.(0)
in
Unix.ADDR_INET(inetaddr, port);;

let run s host_port =
Unix.connect s (sockaddr_from_host_port host_port)
Unix.close s;;

let _ =
run Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 ("127.0.0.1", 666);;


but when I compile, I get this:


ocamlc -custom -o client unix.cma -cclib -lunix client.ml
File "client.ml", line 17, characters 4-16:
This function is applied to too many arguments


If I take out the Unix.close s;; line, it compiles, and if I take out the Unix.connect line, it compiles, so I'm guessing functions can only be one line (or have to use 'in' with everything, but that doesn't seem to work either).

If anyone can give me some pointers on what to do and when, in other cases, I might need to do it, I'd really appreciate it.

Thanks.

Energon
01-22-2003, 01:23 AM
Well, what didn't work yesterday... worked today... and I now have my first (albiet very imperative) o'caml source written up.