package traverse

  1. Overview
  2. Docs
Traversable data structures with applicative functors

Install

Dune Dependency

Authors

Maintainers

Sources

v0.3.0.tar.gz
sha512=a29798bf912dc2c2ddce06aafc63f88fce4bf5dd35884c2e2c7b7caa1b2d8e95122e6f6d3b675965145853f530fad856740201f2f349561a15e78591a56e10fe

doc/src/traverse.traverse_meta/traverse_meta.ml.html

Source file traverse_meta.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
let variable_count = 32

let mklid s =
  Metapp.mkloc (Longident.Lident s)

let rec compose_n n f unit =
  if n > 0 then
    let i = pred n in
    compose_n i f (f i unit)
  else
    unit

let compose f unit =
  compose_n variable_count f unit

let type_of_string s =
  Ppxlib.Ast_helper.Typ.constr (mklid s) []

let mk_t f =
  Ppxlib.Ast_helper.Typ.constr (mklid "t")
    [compose (fun i acc ->
      let ti, ti_t = f i in
      Ppxlib.Ast_helper.Typ.tuple [ti; ti_t; acc])
      (type_of_string "unit")]

let newtypes f expr =
  compose (fun i acc ->
    Metapp.Exp.newtype (Metapp.mkloc (f i)) acc) expr

let ti i = Printf.sprintf "t%d" i

let ti_t i = Printf.sprintf "t%d_t" i

let eqi i = Printf.sprintf "eq%d" i
OCaml

Innovation. Community. Security.