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

Have you thought about adding [%derive.pp: <some-type>] ? #293

Open
chetmurthy opened this issue Jan 1, 2025 · 5 comments
Open

Have you thought about adding [%derive.pp: <some-type>] ? #293

chetmurthy opened this issue Jan 1, 2025 · 5 comments

Comments

@chetmurthy
Copy link

there's [%show: int] etc, and that's useful. But I thought it mgiht be useful to have the same for Format-based pp-functions. I'm contemplating adding it to pa_ppx.deriving_plugins.show, and figured I'd see if you guys wanted to add the same here.

@cuihtlauac
Copy link

cuihtlauac commented Jan 17, 2025

there's [%show: int] etc, and that's useful.

Useful indeed, and a pp-function thing would also be. It may even fix bugs:

type i = {
  j: int;
}

let f = [%show: i]
Error: Unbound value pp_i

A %% extension node is probably needed to handle the mutual recursion between pp and show.

@chetmurthy
Copy link
Author

Um, I don't follow you. The type i is not annotated for deriving, so obviously it won't work. But this small change

# type i = {
  j: int;
}[@@deriving show]
let f = [%show: i] ;;
type i = { j : int; }
val pp_i :
  Ppx_deriving_runtime.Format.formatter -> i -> Ppx_deriving_runtime.unit =
  <fun>
val show_i : i -> Ppx_deriving_runtime.string = <fun>
val f : i -> string = <fun>

makes it work fine. Was there something else you were pointing-out?

@cuihtlauac
Copy link

cuihtlauac commented Jan 17, 2025

I'm looking for a means to derive over types defined in dependencies that I don't want to change or duplicate. Does this make sense?

@chetmurthy
Copy link
Author

Right, for that you can use ppx_import, yes? I do that pretty frequently.

@cuihtlauac
Copy link

It does the job. Thanks. I hadn't spotted that pattern yet. I'd also use what you're proposing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants