mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-19 07:37:56 +03:00
33 lines
564 B
Plaintext
33 lines
564 B
Plaintext
# This program allocates a tree with True at the leaves then parallel ANDs them.
|
|
type Bool:
|
|
True
|
|
False
|
|
|
|
type Tree:
|
|
Node { ~lft, ~rgt }
|
|
Leaf { val }
|
|
|
|
def and(a, b):
|
|
match a:
|
|
case Bool/True:
|
|
return b
|
|
case Bool/False:
|
|
return Bool/False
|
|
|
|
def all(tree):
|
|
fold tree:
|
|
case Tree/Node:
|
|
return and(tree.lft, tree.rgt)
|
|
case Tree/Leaf:
|
|
return tree.val
|
|
|
|
def gen(n):
|
|
switch n:
|
|
case 0:
|
|
return Tree/Leaf(Bool/True)
|
|
case _:
|
|
return Tree/Node { lft: gen(n-1), rgt: gen(n-1) }
|
|
|
|
def main():
|
|
return all(gen(8))
|