package smtml

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

Source file smtml_prelude.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(* SPDX-License-Identifier: MIT *)
(* Copyright (C) 2023-2024 formalsec *)
(* Written by the Smtml programmers *)

include Prelude

module Option = struct
  include Option

  let ( let* ) v f = bind v f

  let ( let+ ) v f = map f v
end

module Result = struct
  include Result

  let ( let* ) v f = Result.bind v f

  let ( let+ ) v f = Result.map f v

  let rec list_iter f = function
    | [] -> Ok ()
    | hd :: tl ->
      let* () = f hd in
      list_iter f tl

  let list_map f v =
    let rec list_map_cps f v k =
      match v with
      | [] -> k (Ok [])
      | hd :: tl ->
        list_map_cps f tl (fun rest ->
          let* rest in
          let* hd' = f hd in
          k (Ok (hd' :: rest)) )
    in
    list_map_cps f v Fun.id

  let list_filter_map f v =
    let rec list_filter_map_cps f v k =
      match v with
      | [] -> k (Ok [])
      | hd :: tl ->
        list_filter_map_cps f tl (fun rest ->
          let* rest in
          let* v = f hd in
          k (Ok (match v with None -> rest | Some v -> v :: rest)) )
    in
    list_filter_map_cps f v Fun.id
end
OCaml

Innovation. Community. Security.