入出力練習

http://mirror.ocamlcore.org/ocaml-tutorial.org/ja/file_manipulation.html
http://mirror.ocamlcore.org/ocaml-tutorial.org/ja/if_statements,_loops_and_recursion.html
を参考に練習。

cat.ml

let read_and_write in_ch out_ch=
  let rec loop ()=
    let line=input_line in_ch in
    output_string out_ch line;
    output_char out_ch '\n';
    flush out_ch;
    loop ()
  in
  try
    loop ()
  with
    End_of_file -> ()
;;

let _=
  if (Array.length Sys.argv)>1 then
    for i=1 to Array.length Sys.argv-1 do
      let in_ch=open_in Sys.argv.(1) in
      read_and_write in_ch stdout;
      close_in in_ch
    done
  else
    read_and_write stdin stdout
;;

stdin
stdout
open_in, close_in
open_out, close_out
output_xxx
input_xxx
flush
あたりが標準の入出力関数らしい。

あと
print_xxxは、output_xxx stdoutのショートカットぽい。