3 ms·
Unfortunately, there is no type inference system (that I know of) that can handle types that programmers use in dynamically typed languages on a daily basis. Fo
by tomp 15y ago
Unfortunately, there is no type inference system (that I know of) that can handle types that programmers use in dynamically typed languages on a daily basis. For example, consider the Django admin property 'list_filter' [1] or the Clojure metaprogramming functions 'proxy' [2] and 'defrecord' [3].
[1] https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter https://docs.djangoproject.com/en/dev/ref/contrib/admin/#dja...
[2] http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/proxy http://clojure.github.com/clojure/clojure.core-api.html#cloj...
[3] http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/defrecord http://clojure.github.com/clojure/clojure.core-api.html#cloj...
- Peaker 15y agolist_filter seems to be a closed sum type -- why do you think it's not simple to encode or infer as a static type? I'm not sure what Proxy is used for -- but it sounds like Template Haskell can probably implement it? defrecord seems like it refers to defining new types at runtime -- which is also possible via either late type-check or Template Haskell.
- tomp 15y agoActually, 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.