package OCanren-ppx

  1. Overview
  2. Docs
Implementation of miniKanren relational (logic) EDSL: PPX extensions

Install

Dune Dependency

Authors

Maintainers

Sources

0.3.0.tar.gz
sha256=eaf9624bbdbae8050eb43a48c0e79e97160b83b6f65a543ee1beca4c9f4ff4b2
sha512=e55dd7a3026b1dedcd37f55181059dfa44ad6976d241a1199246ee3c1684dcfdf1ae0c1da32165b5b2eb5748cfc57c906a0f0ebab56d03035a5bb87187a63cf7

doc/src/ppx_repr/ppx_repr.ml.html

Source file ppx_repr.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
(*
 * OCanren. PPX suntax extensions.
 * Copyright (C) 2015-2021
 * Dmitri Boulytchev, Dmitry Kosarev, Alexey Syomin, Evgeny Moiseenko
 * St.Petersburg State University, JetBrains Research
 *
 * This software is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License version 2, as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU Library General Public License version 2 for more details
 * (enclosed in the file COPYING).
 *)

open Ppxlib

let string_of_expression e =
  Format.set_margin 1000;
  Format.set_max_indent 2000;
  let ans = Format.asprintf "%a" Pprintast.expression e in
  ans
;;

let mapper =
  object
    inherit Ast_traverse.map as super

    method! expression e =
      match e with
      | { pexp_desc = Pexp_construct ({ txt = Lident "REPR"; _ }, Some e); _ } as expr ->
        let text = string_of_expression e in
        { expr with
          pexp_desc =
            Pexp_tuple
              [ Ast_helper.Exp.constant (Pconst_string (text, e.pexp_loc, None)); e ]
        }
      | e -> super#expression e
  end
;;

let () = Ppxlib.Driver.register_transformation ~impl:(fun s -> mapper#structure s) "repr"
OCaml

Innovation. Community. Security.