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_noinjected/ppx_noinjected.ml.html

Source file ppx_noinjected.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
52
53
54
55
56
57
58
(*
  Do not use it yet!

  converts code like
    val x : int * int * int [@@noinjected]
  into
    val x :
      (asdf, qwerty) injected ->
        (asdf, qwerty) injected -> (asdf, qwerty) injected -> goal

  The main issue is to select right mangling of types
*)

open Base
open Ppxlib
open Ppxlib.Ast_builder.Default
open Printf

let name = "noinjected"

exception AttrFound of attribute

let find_good_attribute attrs =
  try
    List.iter attrs ~f:(fun ({attr_name} as attr) ->
        if String.equal attr_name.txt name then raise (AttrFound attr)
      );
    None
  with AttrFound attr ->
    Some attr

let obj = object(self)
  inherit Ast_traverse.map as super
  method! signature_item ss =
    match ss.psig_desc with
    | Psig_value vd -> begin
        match find_good_attribute vd.pval_attributes with
        | None -> ss
        | Some attr ->
          Attribute.explicitly_drop#value_description vd;
          let new_typ =
            match vd.pval_type.ptyp_desc with
            | Ptyp_tuple ts ->
              let loc = vd.pval_loc in
              List.fold_right ts
                ~init:[%type: goal]
                ~f:(fun t ->
                    ptyp_arrow ~loc Nolabel [%type: (asdf,qwerty) injected])
            | _ -> failwith "not yet implemented"
          in
          {ss with psig_desc= Psig_value { vd with pval_type = new_typ}}
      end
    | _ -> ss
end

let () =
  (* Format.printf "Registering `%s`\n%!" name; *)
  Ppxlib.Driver.register_transformation ~intf:obj#signature "noinjected"
OCaml

Innovation. Community. Security.