package frama-c

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Filesystem.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
      error

When 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, 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
OCaml

Innovation. Community. Security.