You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/OCaml-call-JS.md
+9-10Lines changed: 9 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,19 +33,18 @@ improve the generated code.
33
33
}
34
34
|}]
35
35
```
36
-
In the expression level, i.e, `[%bs.raw ...]` user can add a type annotation, the compiler would use such type annotation to deduce its arities. for example, the next three versions:
36
+
In the expression level, i.e, `[%bs.raw ...]` user can add a type
37
+
annotation, for example:
37
38
38
39
```ocaml
39
-
let f = [%bs.raw ("Math.max" : float -> float -> float) ] 3.0
40
-
let f : float -> float -> float = [%bs.raw "Math.max" ] 3.0
41
-
let f = ([%bs.raw "Math.max"] : float -> float -> float ) 3.0
40
+
let f : float * float -> float [@uncurry] = [%bs.raw "Math.max" ]
41
+
in f (3.0, 2.0) [@uncurry]
42
42
```
43
43
will be translated into
44
44
45
45
```js
46
-
functionf(prim){
47
-
returnMath.max(3.0,prim);
48
-
}
46
+
var f =Math.max ;
47
+
f(3.0,2.0)
49
48
```
50
49
Caveat:
51
50
1. So far we don't do any sanity check in the quoted text (syntax check is a long-term goal)
@@ -220,7 +219,7 @@ On top of this we can write normal OCaml functions, for example:
220
219
```OCaml
221
220
let assert_equal = eq
222
221
let from_suites name suite =
223
-
describe name (fun%uncurry () ->
222
+
describe name (fun [@uncurry] () ->
224
223
List.iter (fun (name, code) -> it name code) suite)
225
224
```
226
225
@@ -271,8 +270,8 @@ val f : < hi : ('a * 'b -> 'c [@uncurry] ; .. > Js.t -> 'a -> 'b -> 'c
271
270
This attribute helps create JavaScript object literal
272
271
273
272
```ocaml
274
-
let a = f ({ hi = fun %uncurry (x,y) -> x + y}[@bs.obj]) 1 2
275
-
let b = f ({ hi = fun %uncurry (x,y) -> x +. y}[@bs.obj]) 1. 2.
273
+
let a = f ({ hi = fun [@uncurry] (x,y) -> x + y}[@bs.obj]) 1 2
274
+
let b = f ({ hi = fun [@uncurry] (x,y) -> x +. y}[@bs.obj]) 1. 2.
0 commit comments