From 163a82655b1b3649c9bff4db05f487db3a992a40 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Wed, 8 Nov 2017 17:01:04 +0100 Subject: Update functions --- scTypes.ml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'scTypes.ml') diff --git a/scTypes.ml b/scTypes.ml index 075f25d..48e4d3c 100755 --- a/scTypes.ml +++ b/scTypes.ml @@ -127,7 +127,7 @@ module Type = struct show_list printer buffer tl end - and show: type a. UTF8.Buffer.buffer -> a types -> unit = fun buffer -> begin function + let show: type a. UTF8.Buffer.buffer -> a types -> unit = fun buffer -> begin function | Str x -> UTF8.Buffer.add_string buffer x | Bool b -> UTF8.Printf.bprintf buffer "%B" b | Num (Number, n) -> @@ -146,6 +146,25 @@ module Type = struct UTF8.Printf.bprintf buffer "%d/%d/%d" y m d end + let show_full: type a. UTF8.Buffer.buffer -> a types -> unit = fun buffer -> begin function + | Str x -> UTF8.Buffer.add_string buffer x + | Bool b -> UTF8.Printf.bprintf buffer "%B" b + | Num (Number, n) -> + 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 "%f" f; + Format.pp_print_flush to_b () + | Num (Date, n) -> + let y, m, d = DataType.Date.date_from_julian_day n in + UTF8.Printf.bprintf buffer "%d/%d/%d" y m d + end + type t = | Value: 'a dataFormat * 'a -> t -- cgit v1.2.3