Feature Request - Dynamic Interface for DLR (Dynamic Language Runtime) #2381
Replies: 11 comments
-
Very similar proposal: #2290. |
Beta Was this translation helpful? Give feedback.
-
@svick Similar but Purpose here is different. |
Beta Was this translation helpful? Give feedback.
-
This falls into the body of work that the team is already exploring for more structural-based typing and extensions: |
Beta Was this translation helpful? Give feedback.
-
@HaloFour I tried looking at each interface, I don't understand how extensions or roles will solve this problem? None of these issues talk about |
Beta Was this translation helpful? Give feedback.
-
They have nothing to do with the DLR or dynamic. They have to do with taking a type that doesn't implement an interface and allowing it to do. Your proposal doesn't seem to have much to do with dynamic either. You want a nominal type of members that the compiler enforces a target type conform to and you want consumption of that type to be further enforced by the compiler by only those members. That's pretty much the exact opposite of what You're looking to have |
Beta Was this translation helpful? Give feedback.
-
Is this what you are looking for: https://github.com/ekonbenefits/impromptu-interface |
Beta Was this translation helpful? Give feedback.
-
Isn't this just shapes from #192? |
Beta Was this translation helpful? Give feedback.
-
@HaloFour What if the type is not inside the current assembly, it is already a type defined somewhere else. How would you implement without using DLR? Will role allow us to assign enforcement to an external type? |
Beta Was this translation helpful? Give feedback.
-
Those kinds of details are still being worked out, but the initial "shapes" proposal would emit a "witness struct" which would serve to bridge between the interface and the target type. That struct would either directly call matching members on the target instance or would bind to compatible extension members, both of which would be resolved at compile time. In the "shapes" proposal the consumer of the shape interface would be generic with the implementation constrained to the interface and |
Beta Was this translation helpful? Give feedback.
-
This is exactly what I do not want, that is the whole purpose of dynamic language runtime, and that is why I mentioned dynamic language runtime again and again. You don't seem to understand the problem. If assembly is loaded on runtime, or compiled dynamically, how can we expect it to resolve at compile time? |
Beta Was this translation helpful? Give feedback.
-
Then the DLR will emit a class which they can be resolved against. That's how it works internally. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Dynamic keyword allows us to access members without implementing a known interface and without knowing type (For use in DLR - Dynamic Language Runtime). Pretty much like how TypeScript uses interface.
But it leads to many issues when member names are named inconsistently and very difficult to enforce any naming convention.
Dynamic Interface, dynamic interface does not exist at runtime, it only assists compiler to detect possible errors and warn. Anyone trying to implement dynamically marked interface will get an error that it is not possible.
Benefits
Overhead
Beta Was this translation helpful? Give feedback.
All reactions