import Base # Atom is the caller's schema-bound heterogeneous condition shape. Env is only # captured machine metadata; the world and its component owners remain Type. type Tree is Data: Leaf{atom: Atom} Constant{value: Bool} Negate{inner: Tree} Both{left: Tree,right: Tree} Either{left: Tree,right: Tree} def all(~Atom: Data,items: List<&2,Tree>) -> Tree: match items: case Nil{}: Constant{True{}} case Con{head,tail}: Both{head,all(~Atom,tail)} def any(~Atom: Data,items: List<&2,Tree>) -> Tree: match items: case Nil{}: Constant{False{}} case Con{head,tail}: Either{head,any(~Atom,tail)} def both_next(~Env: Data,first: Bool,env: Env,next: Env -> Bool) -> Bool: match first: case False{}: False{} case True{}: next(env) def either_next(~Env: Data,first: Bool,env: Env,next: Env -> Bool) -> Bool: match first: case False{}: next(env) case True{}: True{} def evaluate(~Atom: Data,~Env: Data,~leaf: Atom -> Env -> Bool,tree: Tree,+env: Env) -> Bool: match tree: case Leaf{atom}: leaf(atom,env) case Constant{value}: value case Negate{inner}: Bool.not(evaluate(~Atom,~Env,~leaf,inner,env)) case Both{left,right}: both_next(~Env,evaluate(~Atom,~Env,~leaf,left,env),env,env => evaluate(~Atom,~Env,~leaf,right,env)) case Either{left,right}: either_next(~Env,evaluate(~Atom,~Env,~leaf,left,env),env,env => evaluate(~Atom,~Env,~leaf,right,env))