From 86262701f0d497bbc8e6c36ac8611f4c9b721bfd Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Tue, 7 Nov 2023 10:25:50 +0000 Subject: [PATCH 1/2] add test for mel.uncurry --- test/blackbox-tests/mel-uncurry-nesting.t | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/blackbox-tests/mel-uncurry-nesting.t diff --git a/test/blackbox-tests/mel-uncurry-nesting.t b/test/blackbox-tests/mel-uncurry-nesting.t new file mode 100644 index 0000000000..c62c7fe48f --- /dev/null +++ b/test/blackbox-tests/mel-uncurry-nesting.t @@ -0,0 +1,49 @@ +Test the attribute @mel.uncurry at different level of nesting + + $ . ./setup.sh + + $ cat > dune-project < (lang dune 3.8) + > (using melange 0.1) + > EOF + + $ cat > dune < (melange.emit + > (target out) + > (emit_stdlib false) + > (preprocess (pps melange.ppx))) + > EOF + +Normal uncurry at first level works fine + + $ cat > x.ml <<\EOF + > external foo : ((unit -> unit)[@mel.uncurry]) -> unit + > = "foo" + > EOF + + $ dune build @melange + +Using `mel.uncurry` at 2nd level of callbacks raises some alerts + + $ cat > x.ml <<\EOF + > external foo : + > (((unit -> unit)[@mel.uncurry]) -> (unit -> unit[@mel.uncurry])) -> unit + > = "foo" + > EOF + + $ dune build @melange + File "x.ml", line 2, characters 20-31: + 2 | (((unit -> unit)[@mel.uncurry]) -> (unit -> unit[@mel.uncurry])) -> unit + ^^^^^^^^^^^ + Alert unused: Unused attribute [@mel.uncurry] + This means such annotation is not annotated properly. + For example, some annotations are only meaningful in externals + + + File "x.ml", line 2, characters 52-63: + 2 | (((unit -> unit)[@mel.uncurry]) -> (unit -> unit[@mel.uncurry])) -> unit + ^^^^^^^^^^^ + Alert unused: Unused attribute [@mel.uncurry] + This means such annotation is not annotated properly. + For example, some annotations are only meaningful in externals + From a9ad3c06c47100a70907b9888727a94db321027c Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Sun, 3 Dec 2023 17:31:53 -0800 Subject: [PATCH 2/2] show how to write uncurried nested functions (needs `[@u]`) --- test/blackbox-tests/mel-uncurry-nesting.t | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/blackbox-tests/mel-uncurry-nesting.t b/test/blackbox-tests/mel-uncurry-nesting.t index c62c7fe48f..3081fd6cc8 100644 --- a/test/blackbox-tests/mel-uncurry-nesting.t +++ b/test/blackbox-tests/mel-uncurry-nesting.t @@ -16,7 +16,7 @@ Test the attribute @mel.uncurry at different level of nesting Normal uncurry at first level works fine - $ cat > x.ml <<\EOF + $ cat > x.ml < external foo : ((unit -> unit)[@mel.uncurry]) -> unit > = "foo" > EOF @@ -25,12 +25,11 @@ Normal uncurry at first level works fine Using `mel.uncurry` at 2nd level of callbacks raises some alerts - $ cat > x.ml <<\EOF + $ cat > x.ml < external foo : > (((unit -> unit)[@mel.uncurry]) -> (unit -> unit[@mel.uncurry])) -> unit > = "foo" > EOF - $ dune build @melange File "x.ml", line 2, characters 20-31: 2 | (((unit -> unit)[@mel.uncurry]) -> (unit -> unit[@mel.uncurry])) -> unit @@ -47,3 +46,13 @@ Using `mel.uncurry` at 2nd level of callbacks raises some alerts This means such annotation is not annotated properly. For example, some annotations are only meaningful in externals + + +In the case of uncurry nesting, we have to resort to the `[@u]` attribute + + $ cat > x.ml < external foo : (((unit -> unit)[@u]) -> unit) -> unit = "foo" + > let () = foo (fun f -> f () [@u]) + > EOF + $ dune build @melange +