I’m not sure what “LMS” is in this context, but the code you’re showing doesn’t seem to make sense as such. Can you show what you’re trying to do in more detail, maybe as a scalafiddle? In general, I’d usually tackle problems like this using a typeclass, but I don’t even understand what you think it ought to do…

In the context of Expression Problem (EP), the very oldest research paper is the most related.

Now, the idea in the code is that one likes to add both new cases to NA.Exp and new functions defined on it – without touching NA. NAM adds the Mul case but fails to add the * method. It, of course, is possible to use implicits as follows instead of extending Exp:

Sorry, I somehow to took it for granted in Scala. LMS = Lightweight Modular Staging.

Interesting. Looks quite useful for certain use cases, but I hadn’t come across it before. Seems like it might be a bit old, though – the front example is using the not-much-loved Manifest, and the “docs” link is broken.

But as I’d expect, the example on the front page is parameterizing over typeclasses. That’s usually the way I would expect to tackle a problem like this – indeed, the Expression Problem is the most common example I usually see for typeclasses. As you’re finding, doing it with inheritance gets problematic quickly…

I’m wondering whether that’s a real limitation? Or, can it be worked around?

Well, almost anything can be worked around, if you’re willing to do a lot of boilerplate and duplication. But this sort of thing is the reason why typeclasses are increasingly common in idiomatic Scala code: they’re often the cleanest, least-boilerplatey solution to these sorts of problems…