1 import Base 2 3 # Atom is the caller's schema-bound heterogeneous condition shape. Env is only 4 # captured machine metadata; the world and its component owners remain Type. 5 type Tree is Data: 6 Leaf{atom: Atom} 7 Constant{value: Bool} 8 Negate{inner: Tree} 9 Both{left: Tree,right: Tree} 10 Either{left: Tree,right: Tree} 11 12 def all(~Atom: Data,items: List<&2,Tree>) -> Tree: 13 match items: 14 case Nil{}: Constant{True{}} 15 case Con{head,tail}: Both{head,all(~Atom,tail)} 16 def any(~Atom: Data,items: List<&2,Tree>) -> Tree: 17 match items: 18 case Nil{}: Constant{False{}} 19 case Con{head,tail}: Either{head,any(~Atom,tail)} 20 21 def both_next(~Env: Data,first: Bool,env: Env,next: Env -> Bool) -> Bool: 22 match first: 23 case False{}: False{} 24 case True{}: next(env) 25 def either_next(~Env: Data,first: Bool,env: Env,next: Env -> Bool) -> Bool: 26 match first: 27 case False{}: next(env) 28 case True{}: True{} 29 30 def evaluate(~Atom: Data,~Env: Data,~leaf: Atom -> Env -> Bool,tree: Tree,+env: Env) -> Bool: 31 match tree: 32 case Leaf{atom}: leaf(atom,env) 33 case Constant{value}: value 34 case Negate{inner}: Bool.not(evaluate(~Atom,~Env,~leaf,inner,env)) 35 case Both{left,right}: both_next(~Env,evaluate(~Atom,~Env,~leaf,left,env),env,env => evaluate(~Atom,~Env,~leaf,right,env)) 36 case Either{left,right}: either_next(~Env,evaluate(~Atom,~Env,~leaf,left,env),env,env => evaluate(~Atom,~Env,~leaf,right,env))