4 ms·
Something like spec in Clojure can be used for something like validations; you have basically a full context-free-grammar syntax to play with (sort of disguised
by tombert 7y ago
Something like spec in Clojure can be used for something like validations; you have basically a full context-free-grammar syntax to play with (sort of disguised as a type-system) that makes validations (in my opinion) a lot simpler than trying to do your own regex-and-split glue. You can use it to validate web forms, or just for sanity-checking data.
Since most people write some level of unit-testing for Clojure anyway, adding spec type-signature functions gives you something like a compile-time typecheck that is relatively easy to add to your CI or simply by invoking `lein test`. In combination with generative testing, being able to have a CFG system to use for your types ends up being a lot more powerful than Hindley-Milner, closer to a dependently-typed system.
Also, while I'm reasonably certain that spec doesn't do this, it's not unreasonable to think that a runtime type system could be used for optimizations that can't be fully known during compile-time.