main.expHover any symbol for live inferred types & effects
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
exporttypeShapeCircle(radius:Float)Rect(w:Float,h:Float)end--- Compute the area of a geometric shape.exportfnarea(shape)matchshapewithCircle(r)thenFloat.pi*r*rRect(w,h)ifw==hthenw*wRect(w,h)thenw*hendendexportfntotalArea(shapes)sum=0.0forsinshapesdosum=sum+area(s)endsumendfnmain()shapes=[Circle(3.0),Rect(4.0,4.0),Rect(2.0,5.0)]print("total area = {totalArea(shapes):.2}")end
Sandboxed ES2022+ Worker
Click Run or press Ctrl+Enter to execute the compiled ES2022+ JavaScript directly in an isolated Web Worker.