3 ms·
So you might be able to use some kind of linter to enforce that you only ever call default(MA) where MA: struct, but even then, is it safe to assume that defaul
by lmm 9y ago
So you might be able to use some kind of linter to enforce that you only ever call default(MA) where MA: struct, but even then, is it safe to assume that default(x) instantiates x in a valid state for all structs? Wouldn't that then mean that e.g. you couldn't ever use a struct containing a reference type anywhere in your codebase, since if you do then default(x) initialises that struct to contain a null reference, right?
- louthy 9y agoThe structs used as ‘class instaces’ aren’t statefull. The compiler will actually optimise out the ‘default’ also, so it’s as efficient as calling a static method. Anyway, nobody is arguing that this is some perfect system, merely that return type polymorphism can be achieved _relatively_ painlessly in a language other than Haskell.