progs/fun/add.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 10 Oct 2022 15:15:15 +0100
changeset 888 fc812b8f120f
parent 814 1fbaa5f05516
permissions -rw-r--r--
texupdate
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
814
1fbaa5f05516 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
1fbaa5f05516 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
1fbaa5f05516 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
def add(x, y) =
1fbaa5f05516 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
  if x == 0 then y else 1 + (add(x - 1, y));
1fbaa5f05516 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
1fbaa5f05516 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
def addT(x, y) =
1fbaa5f05516 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
  if x == 0 then y else addT(x - 1, y + 1);
1fbaa5f05516 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
1fbaa5f05516 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
(write(add(1000, 1000)); addT(100000,100000))
1fbaa5f05516 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10