/
test.phs
53 lines (39 loc) · 993 Bytes
/
test.phs
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
showInt: Int => String
= (x: Int) => `$x.toString()`: String;
showChar: Char => String
= (x: Char) => `$x.toString()`: String;
showBool: Bool => String
= [
(true) => "true";
(false) => "false";
];
random: {Float} = `() => Math.random()`: {Float};
showFloat: Float => String
= (x: Float) => `$x.toString()`: String;
log: String => {Unit}
= (x: String) => `() => console.log($x)`: {Unit};
add: Int => Int => Int
= (x: Int) => (y: Int) => `($x + $y)`: Int;
/* ---------------------------------- */
data Nat: * [
Zero: Nat;
Succ: Nat => Nat;
];
natToInt: Nat => Int
= [
(Zero) => 0;
(Succ(n: Nat)) => add(1, natToInt(n));
];
addN: Nat => Nat => Nat
= [
(Zero) => (y: Nat) => y;
(Succ(x: Nat)) => (y: Nat) => Succ(addN(x, y));
];
three: Nat = Succ(Succ(Succ(Zero)));
four: Nat = Succ(three);
main: {Unit} = do{
x: Float =< random;
log(showFloat(x));
maybeSeven: Nat = addN(three, four);
log(showInt(natToInt(maybeSeven)));
};