|
|
|
|
|
by zastrowm
3348 days ago
|
|
> A dynamic type is probably just implemented as a tagged bit of data, surely A dynamic "type" is really just `object` whose methods are looked up at run time. It's not tagged data at all. See [1] for more info, specifically the example(s) at the bottom, as the reflection code is what gets executed at run (albeit with caching so that methods aren't looked up all the time). `dynamic` is a complex feature that enables multiple dispatch as a side-effect, but only because it allows a whole lot more. [1]: https://visualstudiomagazine.com/Articles/2011/02/01/Underst... > what arguments could you pass in to the statically typed function that would cause the use of dynamic to bite you in the ass public void Output(int value);
public void Output(Person person);
...
dynamic aValue = "Some String";
Output(aValue);
Compiles, because the actual resolving of which overload to call is done at runtime, not at compile time. And at runtime, there is no overload that accepts a string. |
|
Dynamically typed languages usually represent objects as something like a struct with an int tag to represent the type, and a void pointer for its value. The actual reflection going on in the code I posted for multiple dispatch would surely be nothing more than an int comparison - same as what Ocaml probably does.