Frama-C:
Plug-ins:
Libraries:

Frama-C API - Operators

Opening this module allows to use shorter syntax to deal with files.

let open Filepath.Operators in
let result =
  let+ channel = Filepath.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.Normalized.pretty filepath
    error

When the file processing returns a result by itself, the operator let* can be used instead:

let open Filepath.Operators in
let* channel = Filepath.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, string) Stdlib.result
val let* : ('ch, ('a, string) Stdlib.result) safe_processor -> ('ch -> ('a, string) Stdlib.result) -> ('a, string) Stdlib.result

Exception operators

These operators are intended to be used with with_open_in_exn or with_open_out_exn, error Sys_error must be caught.

val let$ : ('ch, 'a) exn_processor -> ('ch -> 'a) -> 'a