3 ms·
also known as structural typing: http://en.wikipedia.org/wiki/Structural_type_system http://en.wikipedia.org/wiki/Structural_type_system
by m0th87 15y ago
also known as structural typing: http://en.wikipedia.org/wiki/Structural_type_system http://en.wikipedia.org/wiki/Structural_type_system
- JoshTriplett 15y agoExactly the term I wanted, thanks! Just didn't manage to remember it. Structural typing allows the creation of functions which only require their inputs to have the specific methods or properties needed to perform the given function, rather than an exact type. Effectively, this creates a minimal supertype for each function, such that the function can accept any subtype of that minimal supertype.
- beza1e1 15y agoThe common bias against structural typing is that there might be types with the same structure but subtly different semantics, e.g. coordinate systems. Same structural type, different semantic: struct carthesian_coords { int x; int y; } struct polar_coords { int r; int theta; }
- JoshTriplett 15y agoMost of the structural typing systems I've seen count the names of fields as part of the type, not just the types of the fields. So, those two structs would have incompatible types in such a system.