diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/attribute.ml | 7 | ||||
| -rw-r--r-- | lib/conventions.ml | 18 | ||||
| -rw-r--r-- | lib/tuple.ml | 17 |
3 files changed, 34 insertions, 8 deletions
diff --git a/lib/attribute.ml b/lib/attribute.ml index 27214b0..f3fc0b1 100644 --- a/lib/attribute.ml +++ b/lib/attribute.ml @@ -1,10 +1,11 @@ -type referenced = { value_hash : Conventions.Hash.t } +type referenced = { value_hash : Conventions.Hash.t } [@@deriving sexp_of] -type materialized = { value: Conventions.AbstractValue.t } +type materialized = { value: Conventions.AbstractValue.t } [@@deriving sexp_of] -type t = +type t = | Referenced of referenced | Materialized of materialized +[@@deriving sexp_of] let make_referenced ~value = let value_hash = Conventions.AbstractValue.hash value in diff --git a/lib/conventions.ml b/lib/conventions.ml index 0019447..60069b0 100644 --- a/lib/conventions.ml +++ b/lib/conventions.ml @@ -2,17 +2,35 @@ module Hash = struct type t = Interop.Sha256.t let hash_text text = Interop.Sha256.compute_hash (Bytes.of_string text) let compare = String.compare + let sexp_of_t = Sexplib.Std.sexp_of_string end module Name = struct type t = string + let sexp_of_t = Sexplib.Std.sexp_of_string end module Cardinality = struct type t = Finite of int | ConstrainedFinite | AlephZero | Continuum + let sexp_of_t = function + | Finite n -> Sexplib.Sexp.(List [Atom "Finite"; Atom (string_of_int n)]) + | ConstrainedFinite -> Sexplib.Sexp.Atom "ConstrainedFinite" + | AlephZero -> Sexplib.Sexp.Atom "AlephZero" + | Continuum -> Sexplib.Sexp.Atom "Continuum" end module AbstractValue = struct type t = Obj.t let hash (elem: t) = Interop.Sha256.compute_hash @@ Marshal.to_bytes elem [] + let sexp_of_t (v : t) = + let open Sexplib.Sexp in + if Obj.is_int v then Atom (string_of_int (Obj.obj v : int)) + else + let tag = Obj.tag v in + if tag = Obj.string_tag then Atom (Obj.obj v : string) + else if tag = Obj.double_tag then + let f = (Obj.obj v : float) in + if Float.is_nan f || Float.is_infinite f then Atom "nan" + else Atom (string_of_float f) + else Atom "<opaque>" end
\ No newline at end of file diff --git a/lib/tuple.ml b/lib/tuple.ml index 3c11fba..11fc508 100644 --- a/lib/tuple.ml +++ b/lib/tuple.ml @@ -1,18 +1,25 @@ -module AttributeMap = Map.Make(String) +module AttributeMap = struct + include Map.Make(String) + let sexp_of_t sexp_of_v m = + Sexplib.Sexp.List + (List.map (fun (k, v) -> Sexplib.Sexp.List [Sexplib.Sexp.Atom k; sexp_of_v v]) + (bindings m)) +end type non_materialized = { hash : Conventions.Hash.t; relation : Conventions.Name.t; attributes : Attribute.referenced AttributeMap.t; -} +} [@@deriving sexp_of] type materialized = { relation: Conventions.Name.t; - attributes: Attribute.materialized AttributeMap.t -} + attributes: Attribute.materialized AttributeMap.t; +} [@@deriving sexp_of] -type t = +type t = | Materialized of materialized | NonMaterialized of non_materialized +[@@deriving sexp_of] let make_materialized ~relation ~attributes = Materialized { relation; attributes } |
