Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type of Pp.paragraphf and add changelog #19

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Unreleased

- Add `Pp.verbatimf`. (#18, @mbarbin)

- Add `Pp.paragraph` and `Pp.paragraphf` (#19, @Alizter)

- Remove `of_fmt` constructor. (#17, @Alizter)

1.2.0
Expand Down
6 changes: 4 additions & 2 deletions src/pp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ include Ast
let of_ast = Fun.id
let to_ast = Fun.id

type ('a, 'tag) format_string = ('a, unit, string, 'tag t) format4

let rec map_tags t ~f =
match t with
| Nop -> Nop
Expand Down Expand Up @@ -145,10 +147,10 @@ let space = break ~nspaces:1 ~shift:0
let cut = break ~nspaces:0 ~shift:0
let newline = Newline
let text s = Text s
let textf fmt = Printf.ksprintf text fmt
let textf (fmt : ('a, 'tag) format_string) = Printf.ksprintf text fmt
let tag tag t = Tag (tag, t)
let paragraph s = hovbox (text s)
let paragraphf fmt = hovbox (textf fmt)
let paragraphf (fmt : ('a, 'tag) format_string) = Printf.ksprintf paragraph fmt

let enumerate l ~f =
vbox
Expand Down
2 changes: 1 addition & 1 deletion src/pp.mli
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alizter I think this change is enough to give you the compile time error on the ml, so you don't need the annotation in the ml once you have this change.

Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ val paragraph : string -> 'tag t

(** [paragraphf s] is [textf s] followed by a [hovbox]. The [textf] version of
[paragraph]. *)
val paragraphf : ('tag t, unit, string, 'b t) format4 -> 'tag t
val paragraphf : ('a, unit, string, 'tag t) format4 -> 'a

(** [enumerate l ~f] produces an enumeration of the form:
Expand Down
3 changes: 3 additions & 0 deletions test/tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,6 @@ let%expect_test "paragraph" =
-< box + text >-----------
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum euismod,
nisl eget aliquam ultricies. |}]

let%expect_test "paragraphf" = print (Pp.paragraphf "Hello World%s" "!");
[%expect {| Hello World! |}]