Variant constructors as functions
Suppose we have:
type t = Foo of int * float
is equal to
fun (x,y) -> Foo (x,y). And,
is equal to
fun x y -> Foo (x,y).
Polymorphic variants as functions
is equivalent to
fun x -> `Foo x
!`Foo always take only one argument:
the arity of the polymorphic variant constructors is at most one
and it is determined purely syntactically.
!`Foo (1,2,3) (* `Foo (1,2,3) *) !`Foo 1 2 3 (* (`Foo 1) 2 3 which ends in a type error *)
(`Foo) has no special meaning. It is just equivalent to
How to build
$ omake $ omake install
opam install ppx_curried_constr.
How to use
$ ocamlfind ocamlc -package ppx_curried_constr ...
You can try examples at
$ ocaml -ppx src/ppx_curried_constr -c -i tests/test.ml
To check the output,
$ src/ppx_curried_constr -debug tests/test.ml
No support of REPL (toplevel)
ppx_currired_constr is a "typeful PPX" which performs typing in it.
It does not work with OCaml REPL (
ocaml command), where ppx commands
are called for each toplevel phrase without carrying over the type environment.
Do you use REPL? Personally, I use it only as a calculator.
(::) is specially handled in OCaml
and it is outside of the support of