3/21/2026 at 1:06:11 AM
For those looking for a broader/more portable introduction, Xavier Leroy and Didier Rémy wrote a great high-level text on UNIX system programming a long time ago [1]. Of course it uses ocaml (perhaps motivating some to learn that language) but the style is low-level and straightforwardly imperative. The advantage is that it sweeps up a lot of the messy and boring error handling into the ocaml runtime and/or exceptions. This makes the code a lot easier to follow, but of course makes it look misleadingly simpler than it would be in C (etc).by discarded1023
3/21/2026 at 1:16:18 AM
Thanks! I just started the OCaml Programming Book this week to learn and language and get better at functional programming. Cant wait to jump into this afterby jacobgeorge08
3/21/2026 at 3:34:22 AM
Why would someone want to learn Unix Programming using OCAML? Not a smart choice. Also this does not look easier to read than a shell script either.let rec copy_rec source dest = let infos = lstat source in match infos.st_kind with | S_REG -> file_copy source dest; set_infos dest infos | S_LNK -> let link = readlink source in symlink link dest | S_DIR -> mkdir dest 0o200; Misc.iter_dir (fun file -> if file <> Filename.current_dir_name && file <> Filename.parent_dir_name then copy_rec (Filename.concat source file) (Filename.concat dest file)) source; set_infos dest infos | _ -> prerr_endline ("Can't cope with special file " ^ source)
by up2isomorphism
3/21/2026 at 10:43:25 AM
OCaml is a weird teaching choice for broad Unix programming, but it makes more sense than bash once the code stops being toy-sized and starts touching files, processes, and error paths in more than one place. Shell scripts let typos turn into state changes, and C gives you the usual memory footguns.That snippet is ugly. Cleaner OCaml is easier to maintain than the average bash blob if you care more about finding mistakes before prod than saving ten minutes on ML syntax.
by hrmtst93837
3/21/2026 at 2:23:58 PM
IMHO modern C (with modern tooling) is very reasonable.by uecker