diff --git a/src/stages/5-ast_typed/PP_json.ml b/src/stages/5-ast_typed/PP_json.ml index 745483ebc..d700c65b3 100644 --- a/src/stages/5-ast_typed/PP_json.ml +++ b/src/stages/5-ast_typed/PP_json.ml @@ -76,13 +76,23 @@ module M = struct `Assoc ["typeVariableMap", `List lst'] ); } - let print : ((no_state, json) fold_config -> no_state -> 'a -> json) -> 'a -> json = fun fold v -> + let to_json : ((no_state, json) fold_config -> no_state -> 'a -> json) -> 'a -> json = fun fold v -> fold to_json NoState v + + let print : ((no_state, json) fold_config -> no_state -> 'a -> json) -> formatter -> 'a -> unit = fun fold ppf v -> + fprintf ppf "%a" Yojson.Basic.pp (to_json fold v) end +module Yojson = Fold.Folds(struct + type in_state = M.no_state ;; + type out_state = json ;; + type 'a t = 'a -> json ;; + let f = M.to_json ;; +end) + include Fold.Folds(struct type in_state = M.no_state ;; type out_state = json ;; - type 'a t = 'a -> json ;; + type 'a t = formatter -> 'a -> unit ;; let f = M.print ;; end) diff --git a/src/stages/5-ast_typed/formatter.ml b/src/stages/5-ast_typed/formatter.ml index f6c331722..e42269786 100644 --- a/src/stages/5-ast_typed/formatter.ml +++ b/src/stages/5-ast_typed/formatter.ml @@ -4,7 +4,7 @@ let program_ppformat ~display_format f (typed,_) = match display_format with | Human_readable | Dev -> PP.program f typed -let program_jsonformat (typed,_) : json = PP_json.program typed +let program_jsonformat (typed,_) : json = PP_json.Yojson.program typed let program_format : 'a format = { pp = program_ppformat;