Skip to content

Commit 158599b

Browse files
committed
Test uncurried cast idea.
When curried application is used for an uncurried function, instead of a type error one gets a curried partial application. This allows e.g. to define curried library functions such as `raise` and use them both with curried and uncurried application.
1 parent 35e35c5 commit 158599b

File tree

7 files changed

+142
-1
lines changed

7 files changed

+142
-1
lines changed

jscomp/ml/typecore.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,6 +2968,7 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
29682968
Location.prerr_warning sarg1.pexp_loc Warnings.Unused_argument;
29692969
unify env ty_fun (newty (Tarrow(l1,t1,t2,Clink(ref Cunknown))));
29702970
(t1, t2)
2971+
| Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),[{desc=Tarrow (l,t1,t2,_)}],_)
29712972
| Tarrow (l,t1,t2,_) when Asttypes.same_arg_label l l1
29722973
->
29732974
(t1, t2)

jscomp/test/build.ninja

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

jscomp/test/uncurried_cast.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
'use strict';
2+
3+
var Curry = require("../../lib/js/curry.js");
4+
var Belt_List = require("../../lib/js/belt_List.js");
5+
var Caml_exceptions = require("../../lib/js/caml_exceptions.js");
6+
7+
function raise(e) {
8+
throw e;
9+
}
10+
11+
var map = Belt_List.mapU;
12+
13+
var List = {
14+
map: map
15+
};
16+
17+
var Uncurried = {
18+
raise: raise,
19+
List: List
20+
};
21+
22+
var E = /* @__PURE__ */Caml_exceptions.create("Uncurried_cast.E");
23+
24+
function testRaise(param) {
25+
throw {
26+
RE_EXN_ID: E,
27+
Error: new Error()
28+
};
29+
}
30+
31+
var l = map({
32+
hd: 1,
33+
tl: {
34+
hd: 2,
35+
tl: /* [] */0
36+
}
37+
}, (function (x) {
38+
return x + 1 | 0;
39+
}));
40+
41+
var partial_arg = {
42+
hd: 1,
43+
tl: {
44+
hd: 2,
45+
tl: /* [] */0
46+
}
47+
};
48+
49+
function partial(param) {
50+
return map(partial_arg, param);
51+
}
52+
53+
var ll = Curry._1(partial, (function (x) {
54+
return x + 1 | 0;
55+
}));
56+
57+
var StandardNotation = {
58+
testRaise: testRaise,
59+
l: l,
60+
partial: partial,
61+
ll: ll
62+
};
63+
64+
function testRaise$1() {
65+
return raise({
66+
RE_EXN_ID: E
67+
});
68+
}
69+
70+
var l$1 = map({
71+
hd: 1,
72+
tl: {
73+
hd: 2,
74+
tl: /* [] */0
75+
}
76+
}, (function (x) {
77+
return x + 1 | 0;
78+
}));
79+
80+
var partial_arg$1 = {
81+
hd: 1,
82+
tl: {
83+
hd: 2,
84+
tl: /* [] */0
85+
}
86+
};
87+
88+
function partial$1(param) {
89+
return map(partial_arg$1, param);
90+
}
91+
92+
var ll$1 = partial$1(function (x) {
93+
return x + 1 | 0;
94+
});
95+
96+
exports.Uncurried = Uncurried;
97+
exports.E = E;
98+
exports.StandardNotation = StandardNotation;
99+
exports.testRaise = testRaise$1;
100+
exports.l = l$1;
101+
exports.partial = partial$1;
102+
exports.ll = ll$1;
103+
/* l Not a pure module */

jscomp/test/uncurried_cast.res

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module Uncurried = {
2+
let raise = (. e) => raise(e)
3+
4+
module List = {
5+
let map = (. l, f) => Belt.List.mapU(l, f)
6+
}
7+
}
8+
9+
exception E
10+
11+
module StandardNotation = {
12+
open Uncurried
13+
14+
let testRaise = () => raise(E)
15+
16+
let l = List.map(.list{1, 2}, (. x) => x + 1)
17+
18+
let partial = List.map(list{1, 2})
19+
20+
let ll = partial((. x) => x + 1)
21+
}
22+
23+
@@uncurried
24+
25+
open Uncurried
26+
27+
let testRaise = () => raise(E)
28+
29+
let l = List.map(list{1, 2}, x => x + 1)
30+
31+
let partial = List.map(. list{1, 2})
32+
33+
let ll = partial(.x => x + 1)

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43666,6 +43666,7 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
4366643666
Location.prerr_warning sarg1.pexp_loc Warnings.Unused_argument;
4366743667
unify env ty_fun (newty (Tarrow(l1,t1,t2,Clink(ref Cunknown))));
4366843668
(t1, t2)
43669+
| Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),[{desc=Tarrow (l,t1,t2,_)}],_)
4366943670
| Tarrow (l,t1,t2,_) when Asttypes.same_arg_label l l1
4367043671
->
4367143672
(t1, t2)

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43666,6 +43666,7 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
4366643666
Location.prerr_warning sarg1.pexp_loc Warnings.Unused_argument;
4366743667
unify env ty_fun (newty (Tarrow(l1,t1,t2,Clink(ref Cunknown))));
4366843668
(t1, t2)
43669+
| Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),[{desc=Tarrow (l,t1,t2,_)}],_)
4366943670
| Tarrow (l,t1,t2,_) when Asttypes.same_arg_label l l1
4367043671
->
4367143672
(t1, t2)

lib/4.06.1/whole_compiler.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98661,6 +98661,7 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
9866198661
Location.prerr_warning sarg1.pexp_loc Warnings.Unused_argument;
9866298662
unify env ty_fun (newty (Tarrow(l1,t1,t2,Clink(ref Cunknown))));
9866398663
(t1, t2)
98664+
| Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),[{desc=Tarrow (l,t1,t2,_)}],_)
9866498665
| Tarrow (l,t1,t2,_) when Asttypes.same_arg_label l l1
9866598666
->
9866698667
(t1, t2)

0 commit comments

Comments
 (0)