Ppx for reifying constructors

In SML (and similarly Haskell), if I write

datatype foo = Foo of int

I can use Foo as a 1st class functional value with type int -> foo. In Ocaml this is not so, I have to write something like (function x -> Foo x) or give this snippet a name and use that. So my question is, is there a ppx which would generate these trivial functions for me automatically?

GitHub - janestreet/ppx_variants_conv: Generation of accessor and iteration functions for ocaml variant types does this and also generates some other useful values based on variants.

Similarly GitHub - janestreet/ppx_fields_conv: Generation of accessor and iteration functions for ocaml records for record fields.

4 Likes