forked from hkust-taco/mlscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
48 lines (42 loc) · 1.29 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
<!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">
type List[A] = Cons[A] | Nil
class Cons[out A](head: A, tail: List[A]) {
fun map: (A -> 'B) -> List['B]
map(f) = Cons of f(head), tail.map(f)
}
module Nil {
fun map(f) = Nil
}
fun (::) cons(x, xs) = Cons(x, xs)
fun show(xs) =
let rec go(xs) = if xs is
Cons(h, Nil) then String(h)
Cons(h, t) then join(String(h), ", ", go(t))
Nil then ""
join("[", go(xs), "]")
let xs = 1 :: 2 :: 3 :: Nil
show(xs)
show(xs.map of x => succ(x))
</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>