In my WIP language, all functions are really just variables with a callable type. That is, a function call
foo(bar) is parsed into the following AST:
All functions defined on structs are similarly stored as callable fields. A method call
foo.bar() is really just the variable access
foo.bar, then a call on the resulting callable.
However, my language also has a typeclass system, like Rust. Unlike structs, traits have to “own” their functions, that is, they cannot simply be fields.
When performing the type checking, as struct members are conceptually fields on the struct, I need to do no extra work. Just access the field and then call it. As far as the type checker is concerned, when it sees a method call, it’s looking at a field access. However, trait methods are not defined as fields. The type checker can’t see that the access is actually a trait method call. How can I resolve this condundrum?