forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.postiats.txt
More file actions
64 lines (62 loc) · 965 Bytes
/
sample.postiats.txt
File metadata and controls
64 lines (62 loc) · 965 Bytes
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
// http://www.ats-lang.org/
(* Say Hello! once *)
val () = print"Hello!\n"
//
(* Say Hello! 3 times *)
val () = 3*delay(print"Hello!")
val () = print_newline((*void*))
//
//
(* Build a list of 3 *)
val xs = $list{int}(0, 1, 2)
//
val x0 = xs[0] // legal
val x1 = xs[1] // legal
val x2 = xs[2] // legal
val x3 = xs[3] // illegal
//
//
extern
fun{} f0 (): int
extern
fun{} f1 (int): int
extern
fun{} repeat_f0f1 (int): int
//
implement
{}(*tmp*)
repeat_f0f1(n) =
if n = 0
then f0()
else f1(repeat_f0f1(n-1))
// end of [if]
//
fun
times (
m:int, n:int
) : int = // m*n
repeat_f0f1 (m) where
{
implement f0<> () = 0
implement f1<> (x) = x + n
}
//
fun
power (
m:int, n:int
) : int = // m^n
repeat_f0f1 (n) where
{
implement f0<> () = 1
implement f1<> (x) = m * x
}
//
val () =
println! ("5*5 = ", times(5,5))
val () =
println! ("5^2 = ", power(5,2))
val () =
println! ("2^10 = ", power(2,10))
val () =
println! ("3^10 = ", power(3,10))
//