Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions archive/o/ocaml/file-input-output.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let filename = "output.txt"

let sample_text =
{|Some mundane sample text
Some sample text that is mundane
Another line of mundane sample text
|}

let () =
(try
Out_channel.with_open_text filename (fun oc ->
Out_channel.output_string oc sample_text)
Comment on lines +11 to +12
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be written 1 line at a time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the way that ocamlformat autoformats the file with the default profile. If you put the lambda on a separate line, it reformats the file back to this. I think for a sample program repository it makes sense to follow the convention set out by the language.

with Sys_error msg ->
Printf.eprintf "Failed to write to '%s': %s\n" filename msg;
exit 1);

(try In_channel.with_open_text filename (fun ic -> In_channel.input_lines ic)
with Sys_error msg ->
Printf.eprintf "Failed to read from '%s': %s\n" filename msg;
exit 1)
|> List.iter print_endline
Loading