aboutsummaryrefslogtreecommitdiff
path: root/src/expressions/show_type.ml
diff options
context:
space:
mode:
Diffstat (limited to 'src/expressions/show_type.ml')
-rwxr-xr-xsrc/expressions/show_type.ml26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/expressions/show_type.ml b/src/expressions/show_type.ml
new file mode 100755
index 0000000..c459dca
--- /dev/null
+++ b/src/expressions/show_type.ml
@@ -0,0 +1,26 @@
+type 'a t = UTF8.Buffer.buffer -> unit
+type 'a obs = UTF8.Buffer.buffer -> unit
+
+let str s buffer =
+ UTF8.Buffer.add_string buffer s
+
+let num n buffer =
+ if DataType.Num.is_integer n then
+ DataType.Num.to_int n
+ |> string_of_int
+ |> UTF8.from_utf8string
+ |> UTF8.Buffer.add_string buffer
+ else
+ let f = DataType.Num.to_float n
+ and to_b = UTF8.Format.formatter_of_buffer buffer in
+ ignore @@ UTF8.Format.fprintf to_b "%.2f" f;
+ Format.pp_print_flush to_b ()
+
+let date n buffer =
+ let y, m, d = DataType.Date.date_from_julian_day n in
+ UTF8.Printf.bprintf buffer "%d/%d/%d" y m d
+
+let bool b buffer =
+ UTF8.Printf.bprintf buffer "%B" b
+
+let observe elem buffer = elem buffer