aboutsummaryrefslogtreecommitdiff
path: root/examples/sum.fwd
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sum.fwd')
-rw-r--r--examples/sum.fwd23
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/sum.fwd b/examples/sum.fwd
new file mode 100644
index 0000000..89a2d11
--- /dev/null
+++ b/examples/sum.fwd
@@ -0,0 +1,23 @@
+print_int(i64 a);
+print_nl();
+
+sum_inner(i64 s, i64 n, (i64) res)
+{
+ if n <= 0 {
+ res(s);
+ } else {
+ sum_inner(s + n, n - 1, res);
+ }
+}
+
+sum(i64 n, (i64) res)
+{
+ sum_inner(0, n, res);
+}
+
+main()
+{
+ sum(1000000000) => i64 s;
+ print_int(s);
+ print_nl();
+}