Created
September 21, 2011 15:32
-
-
Save ichiban/1232383 to your computer and use it in GitHub Desktop.
simple 'cat' command in O'Caml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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