concrete TreeDemo { @type run () -> () } define TreeDemo { run () { TypeTree tree <- TypeTree$new() TypeKey keyInt <- TypeKey$new() TypeKey keyString <- TypeKey$new() TypeKey keyFloat <- TypeKey$new() TypeKey keyValue <- TypeKey$new() \ tree.set(keyInt,1) \ tree.set(keyString,"a") \ check(tree,keyInt) \ check(tree,keyString) \ check(tree,keyFloat) // Not found, since we never added a value. \ tree.set(keyValue,Value$new()) \ check(tree,keyValue) } @category check<#x> #x requires Formatted (TypeTree,TypeKey<#x>) -> () check (tree,key) { scoped { optional #x value <- tree.get<#x>(key) } in if (present(value)) { \ LazyStream$new() .append("Found '") .append(require(value)) .append("'\n") .writeTo(SimpleOutput$stderr()) } else { \ LazyStream$new() .append(typename>()) .append(" Not Found\n") .writeTo(SimpleOutput$stderr()) } } } concrete Value { refines Formatted @type new () -> (Value) } define Value { new () { return Value{} } formatted () { return "Value" } }