The following code tries to mimic Polymorphic Embedding of DSLs: rather than giving the behavior in Inner, it is encoded in the useInner method of
The problem is as you describe, that useInner is expecting an Inner of a specific Outer instance. Since enclosing returns a generic Outer, there is really no way to tie both together that I know of.
You can force it, however:
def toBoolean(x: Outer#Inner): Boolean = {
val outer = x.enclosing
outer.useInner(x.asInstanceOf[outer.Inner])
}