Frama-C API - Operators
Opening this module allows to use shorter syntax to deal with files.
let open Filesystem.Operators in
let result =
let+ channel = Filesystem.with_open_out filepath in
output_string channel "42";
in
match result with
| Ok () -> ()
| Error error ->
Format.printf "error writing to file %a: %s"
Filepath.pretty filepath
errorWhen the file processing returns a result by itself, the operator let* can be used instead:
let open Filesystem.Operators in
let* channel = Filesystem.with_open_in filepath in
try
let header = input_line channel in
if header = "42"
then Ok ()
else Error "wrong file header"
with End_of_file ->
Error "file is empty" Result operators
These operators are intended to be used with with_open_in or with_open_out.
val let+ : ('ch, 'a) safe_processor -> ('ch -> 'a) -> 'a resultval let* : ('ch, 'a result) safe_processor -> ('ch -> 'a result) -> 'a resultSys_error operators
These operators are intended to be used with with_open_in_exn or with_open_out_exn, exception Sys_error must be caught.
val let$ : ('ch, 'a) exn_processor -> ('ch -> 'a) -> 'a