package metapp

  1. Overview
  2. Docs
Meta-preprocessor for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

metapp.0.4.4.tar.gz
sha512=817b33d9006a6849845e29a2b12ad7b7d13e34e38216bd2724df45e8f24356f9d281e2731ecc37a8ab2b5faef844252a04f976adf61d024b7653235e38dfdc46

doc/src/metapp.preutils/accu.ml.html

Source file accu.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
type 'a t = {
    length : int;
    list : 'a list;
  }

let empty = { length = 0; list = [] }

let add value { length; list } =
  length, { length = succ length; list = value :: list }

let length { length; _ } =
  length

let to_array ({ length; list } : 'a t) : 'a array =
  match list with
  | [] -> [||]
  | hd :: tl ->
      let result = Array.make length hd in
      let rec fill i list =
        match list with
        | [] -> ()
        | hd :: tl ->
            result.(i) <- hd;
            fill (pred i) tl in
      fill (length - 2) tl;
      result
OCaml

Innovation. Community. Security.