Skip to content

Instantly share code, notes, and snippets.

@ichiban
Created September 21, 2011 15:32
Show Gist options
  • Save ichiban/1232383 to your computer and use it in GitHub Desktop.
Save ichiban/1232383 to your computer and use it in GitHub Desktop.
simple 'cat' command in O'Caml
(* cat.ml *)
(* simple cat command in O'Caml *)
open Sys
open Array
open List
let print_channel in_channel =
let rec iter _ =
print_endline (input_line in_channel);
iter()
in try iter () with
End_of_file -> close_in in_channel
let cat =
List.iter print_channel
let _ =
match List.tl (Array.to_list Sys.argv) with
| [] -> cat [stdin]
| hd :: tl as filenames -> cat (List.map open_in filenames)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment