The Clojure official spec doc states:
Most systems for specifying structures conflate the specification of the key set (e.g. of keys in a map, fields in an object) with the specification of the values designated by those keys. I.e. in such approaches the schema for a map might say :a-key’s type is x-type and :b-key’s type is y-type. This is a major source of rigidity and redundancy.
And in this SO question: clojure.spec human readable shape?
The following example is given:
(s/def ::car (s/keys :req [::tires ::chassis]))
(s/def ::tires (s/coll-of ::tire :count 4))
(s/def ::tire (s/or :goodyear ::goodyear}
:michelin ::michelin))
My question is: how is this not ridig and not redundant? By opposition to that, what would be and example (in Java?) of something rigid and redundant?
As I see it you still cannot define a car that'd be, say, a dragster with 6 wheels because ::tires
must have 4 elements. You cannot either define a floating car whose rear wheels would be propellers.
How's the above example different from, say, static typing from the standpoint of rigidity and redundancy? How's that different from a Java car
class that'd be constructed using a tires
instance itself containing four tire
instance?
Basically I think what I don't get is that you're spec'ing the map by telling which keys are required. So far so good. But then the keys are themselved spec'ed, so the values designated by those keys are specified too no!? How are things "not conflated" here?