-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
70 lines (61 loc) · 1.83 KB
/
index.html
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="index.css">
<title>MLscript demonstration</title>
</head>
<body>
<h1>ML<sub>script</sub> online demonstration</h1>
<div id="content">
<textarea id="mlscript-input" class="panel" spellcheck="false">
fun power(x) = case
0 then `1.0
n then x `*. power(x)(n - 1)
fun assertNotZero(x) =
`if (x `== `0.0) then `error else x
let checkedDiv = x `=> y `=> x `/ assertNotZero(y)
fun show: Code[anything, anything] -> Str = _ => "debug"
fun inc(dbg) =
x `=> let c = x `+ `1 in dbg(c), c
inc(c => log(show(c)))
fun body_naive(x, y) = case
0 then x
1 then y
n then body_naive(y, x `+ y)(n - 1)
fun gib_naive(n) =
(x, y) `=> body_naive(x, y)(n)
let gn5 = run(gib_naive(5))
fun bind(rhs, k: forall 'g : Code['a, 'g] -> Code['b, 'c | 'g]) =
`let x = rhs `in k(x)
fun body: forall 'g : (Code[Int, 'g], Code[Int, 'g]) -> Int -> Code[Int, 'g]
fun body(x, y) = case
0 then x
1 then y
n then bind of x `+ y, z => body(y, z)(n - 1)
fun gib(n) = ((x, y) `=> body(x, y)(n))
let g5 = run(gib(5))
mut let qq0 = `0
let foo =
mut let r = `0
(x `=> ((set r = x), `0)), r
class Ref[A](init: A) { mut val value: A = init }
let bar = x `=>
let v = Ref(x)
let _ = y `=>
set v.value = y
`0
v.value
</textarea>
<!-- let rec recursive_monster = fun x ->
{ thing = x;
self = recursive_monster x } -->
<div id="mlscript-output" class="panel"></div>
</div>
<script type="text/javascript" src="bin/mlscript-opt.js"></script>
<br/>
<p>The code is available <a href="https://github.com/hkust-taco/mlscript">on github</a>.</p>
<br/>
<p>Note: JavaScript code generation (used to evaluate the result) is not perfect yet and has rough edges.
Also, try typing `window.alert of "Hello!"` and see what happens!</p>
</html>