Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Exactly 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.



The 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; }


Most 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: