dbuenzli / fmt

OCaml Format pretty-printer combinators
http://erratique.ch/software/fmt
ISC License
71 stars 26 forks source link

Dump: fix dumping of sequences #45

Closed edwintorok closed 4 years ago

edwintorok commented 4 years ago

Fix regression introduced in Fmt.0.8.7, where Dump.hashtbl prints no separators anymore:

utop # let h = Hashtbl.create 47 in Hashtbl.add h 1 2; Hashtbl.add h 3 4; Fmt.to_to_string (Fmt.Dump.hashtbl Fmt.int Fmt.int) h;;
- : string = "(hashtbl 34 12)"

Prior to fmt.0.8.7 it used to print separators between keys and values which is more useful:

- : string = "(hashtbl (3, 4)(1, 2))"

Move code around, so that we use the definition of pair from Dump, which adds the proper separators.

dbuenzli commented 4 years ago

Thanks Edwin. Just to make things clear does that restore the previous format exactly ?

edwintorok commented 4 years ago

Not exactly, there is an extra space now (I'd consider that an improvement). I don't particularly mind about the exact format (the docs for Dump make it clear that the exact format is unspecified), as long as there is some separator between keys and values, such that it is unambiguous where the key ends and the value starts.

0.8.8: (hashtbl 510 46) 0.8.6: (hashtbl (5, 10)(4, 6)) this PR: (hashtbl (5, 10) (4, 6))

Small testcase:

let () =
  let x = Hashtbl.create 5 in
  Hashtbl.add x 4 6;
  Hashtbl.add x 5 10;
  Fmt.pf Fmt.stdout "%a@." (Fmt.Dump.hashtbl Fmt.int Fmt.int) x
dbuenzli commented 4 years ago

Thanks what you propose was what I was going to ask your for. Your patch is in as 1662bb0be5f3d9e443