diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-03-09 21:48:51 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-03-09 21:48:51 -0300 |
| commit | c642042536362bba0d3ee0ebf6a6c33a888a0ff5 (patch) | |
| tree | e2684a2758190ab67483156876e35824fc76e708 /lib/conventions.ml | |
| parent | cce3bfba31b32c13ea116a214306d96fe1eb27eb (diff) | |
| download | Sakura-c642042536362bba0d3ee0ebf6a6c33a888a0ff5.tar.gz Sakura-c642042536362bba0d3ee0ebf6a6c33a888a0ff5.zip | |
defenestrate json
Diffstat (limited to 'lib/conventions.ml')
| -rw-r--r-- | lib/conventions.ml | 18 |
1 files changed, 18 insertions, 0 deletions
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 |
