by Drup · 7y ago · 0 comments
There are plenty of real world scenarios where static checking gets in the way even if you're not trying to encode complex properties using the type system.
One problem is that static typing is at odds with modularization since type declarations are considered globally. For example, Ring HTTP abstraction in Clojure represents requests and responses as maps. Middleware functions [1] can update these maps to inject additional keys, or modify existing keys. These functions often live in separate libraries that know nothing about one another. A static type system precludes this since it would require you to provide a static declaration for every possible request and response map.
[1] https://github.com/ring-clojure/ring/wiki/Middleware-Pattern...
If you statically prove that you check that they keys are there before using them, then the type system can be satisfied.
Module X expects the "foo" key, then write a function that checks if it has the foo key and returns a type Maybe(HasFoo). It's less good than just treating the type as the union of HasFoo and HasBar or whatever, but if you fully decouple, then you have to be able to handle the case in which the mapping lacks a foo key anyways, and this will statically froce you to.