[PATCH] Representations for query types
Export this patch
---
dune-project | 2 ++
forester.opam | 1 +
lib/core/Query.ml | 18 +++++++++++++++---
lib/core/dune | 2 +-
4 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/dune-project b/dune-project
index 7ad6a5e..0909fda 100644
--- a/dune-project
+++ b/dune-project
@@ -56,6 +56,8 @@
(>= 7.1.0))
(repr
(>= 0.7.0))
+ (ppx_repr
+ (>= 0.7.0))
(uri
(>= 4.4.0))
(pure-html
diff --git a/forester.opam b/forester.opam
index 0b73470..058a44a 100644
--- a/forester.opam
+++ b/forester.opam
@@ -25,6 +25,7 @@ depends: [
"yojson" {>= "2.1.2"}
"toml" {>= "7.1.0"}
"repr" {>= "0.7.0"}
+ "ppx_repr" {>= "0.7.0"}
"uri" {>= "4.4.0"}
"pure-html" {>= "3.5.0"}
"odoc" {with-doc}
diff --git a/lib/core/Query.ml b/lib/core/Query.ml
index 0eaab5b..45def75 100644
--- a/lib/core/Query.ml
+++ b/lib/core/Query.ml
@@ -19,16 +19,20 @@ type rel = Rel.t
type mode =
| Edges
| Paths
-[@@deriving show]
+[@@deriving show, repr]
type polarity =
| Incoming
| Outgoing
-[@@deriving show]
+[@@deriving show, repr]
type rel_query = mode * polarity * Rel.t
[@@deriving show]
+let rel_query_t =
+ let open Repr in
+ triple mode_t polarity_t Symbol.repr
+
type ('addr, 'r) view =
| Rel of rel_query * 'addr
| Isect of 'r list
@@ -36,11 +40,19 @@ type ('addr, 'r) view =
| Complement of 'r
| Isect_fam of 'r * rel_query
| Union_fam of 'r * rel_query
-[@@deriving show]
+[@@deriving show, repr]
type 'addr t = Q of ('addr, 'addr t) view
[@@deriving show]
+let query_t addr_t =
+ let open Repr in
+ mu
+ (fun query_t -> variant "query"
+ (fun q -> function | Q x -> q x)
+ |~ case1 "Q" (view_t addr_t query_t) (fun x -> Q x)
+ |> sealv)
+
let view (Q q) = q
let make q = Q q
diff --git a/lib/core/dune b/lib/core/dune
index 2c36b04..4c89f09 100644
--- a/lib/core/dune
+++ b/lib/core/dune
@@ -1,7 +1,7 @@
(library
(name Forester_core)
(preprocess
- (pps ppx_deriving.show))
+ (pps ppx_deriving.show ppx_repr))
(libraries forester.prelude yuujinchou asai repr ocamlgraph)
(public_name forester.core))
--
2.45.2