3 ms·
Actually, I didn't mean to type the whole function, but only the parameters... One would require something like union types, e.g. list_filter has type String
by tomp 15y ago
Actually, I didn't mean to type the whole function, but only the parameters... One would require something like union types, e.g. list_filter has type
String | `a < SimpleListFilter | (String, `b < FieldListFilter)
Now, this type is certainly encodable in a modern advanced type system (although most statically typed languages utilize type erasure for compilation, so you would need tagged unions (Algebraic Data Types) for this), but I cannot imagine that any language is capable of inferring such a type. Maybe OCaml, but again, we would need polymorphic variants for that.
- Peaker 15y agoInstead of (a < SimpleListFilter) you can use a type-class constraint and an existential, or an explicit record of methods. In Haskell, anything you use will basically be inferred, and Haskell can encode that, though you would have to choose different primitives to encode that relationship than subtypes.