Skip to content

Instantly share code, notes, and snippets.

@droyo
Created February 19, 2021 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save droyo/2adb11720e2f0265aece175754e1d2bc to your computer and use it in GitHub Desktop.
Save droyo/2adb11720e2f0265aece175754e1d2bc to your computer and use it in GitHub Desktop.
type t = term list
and term =
| Int of int
| Bool of bool
| Float of float
| Id of string
| Str of string
| Expr of t
(* pp_term calls pp *)
let rec pp_term ppf = function
| Int x -> Fmt.int ppf x
| Bool x -> Fmt.bool ppf x
| Float x -> Fmt.float ppf x
| Str x -> Fmt.Dump.string ppf x
| Id x -> Fmt.string ppf x
| Expr x -> pp ppf x
(* and pp calls pp_term *)
and pp ppf ast =
if List.for_all (function Expr _ -> true | _ -> false) ast
then Fmt.(pf ppf "@[<hv 1>(%a)@]" (list ~sep:sp pp_term) ast)
else Fmt.(pf ppf "@[<b 1>(%a)@]" (list ~sep:sp pp_term) ast)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment