bind has signature App x (Node => Node) => Node
_.child in this context means {n: Node => n.child} , and Node does not define a child element. This is an error message.
In your particular case, you can expect it to work because you know that the argument to the bind function is applied to the Node scheme of the application argument. However, you should say almost as much to the compiler. And that will make you make some implementation details more public.
First, perhaps your function will not have a Node argument, but something more precise. You may have a general parameter:
def bind[N <: Node](app: App, f: N => Node)
But then when you call f(app.schema) , you have to make sure that app.schema is of the required type
class App[N <: Node] {def schema: N} def bind[N <: Node](app: App[N], f: N => Node) = f(app.schema)
Finally, you will need to make your application type more explicit, at least
class NodeOfApp{def child: Node} val app = new App[NodeOfApp]{...}
source share