> all type declarations that have not been proven to always hold are asserted at runtime
Also good is that it starts from what the reader knows informally rather than trying to build everything rigorously from the ground up.
It's certainly pragmatic, but is it good? Maybe I'm biased as a math student, but I've seen first-hand the horrors that happen when people think they know something just because they have a vague intuition about the topic's main ideas.
From everything I've read about how mathematicians work, I thought that was normal.
Then they aren't types.
Why are so-called “type hints” interesting in? The real value in a type system is:
(0) Not having to worry about large classes of mistakes. They just don't happen in a legal program.
(1) Enforcing abstractions, i.e., not allowing library users to make decisions based on library implementation details.
(2) Managing the verification effort. Proving that a program meets its specification becomes much easier when components are guaranteed not to violate the assumptions made in each other's design.
A “type system” that can't do any of these is just a waste of engineering effort.
Why? (And what is the antecedent of "it"?)
> that's not a type, since it is trivially unsound
You are misunderstanding what a type is. A type is just a subset of all of the possible data values in a language. Types by themselves don't do anything.
1. CL implementations are free to do static type analysis based on declarations (and some do) and they are also free to signal run-time errors if you assign a value not of the declared type (and some do).
2. Not all storage locations are variables, e.g.:
Welcome to Clozure Common Lisp Version 1.10-r16479M (DarwinX8664)!
? (setf a (make-array 10 :element-type '(unsigned-byte 32)))
#(0 0 0 0 0 0 0 0 0 0)
? (setf (aref a 0) 'foo)
> Error: FOO doesn't match array element type of #<VECTOR 10 type (UNSIGNED-BYTE 32), simple>.
The point is that focusing on "variables" makes tacit assumptions about programming languages that aren't necessarily true."Affects only variable bindings and specifies that the vars take on values only of the specified typespec"
The hyperspec's definition only applies to the hyperspec, not the paper. On the hyperspec's definition, an array cell is not a variable, but it seems very unlikely that this is what the author of the paper intended. It's much more likely that what the author intended by "variable" the CLHS calls a "place". (But this is exactly the problem: we don't know what the author of the paper intended because he didn't say. We have to guess.)
> vars take on values only of the specified typespec
Right, but the spec doesn't actually say what happens when this constraint is violated.
There is no syntax to declare the type of a single cell, you can only put identifiers (symbols), not places, into declarations. Either your variable is declared to hold an array of, say, fixnums, or you bind a variable to the content of a cell and declare the type of that variable.
> Right, but the spec doesn't actually say what happens when this constraint is violated.
The spec says the consequences are undefined. Either you code against the guarantees of your implementation (which are hopefully more precise), or you aim for portability and consistently add check-type before locally declaring types.
> The spec says the consequences are undefined.
Don't those mean the same thing?
At the end of the day, a Zen master tells his student: "your next lesson will start at 5am tomorrow, don't be late"; the student says: "what will happen if I am late?". The master doesn't reply.
The student goes to sleep and wakes up late. "You missed your lesson, come back tomorrow at 4am or else I can't guarantee your safety.". The next day, the student arrives on time.
----
Saying things are undefined is an explicit way of demarcating what is part or not of the specification. Otherwise, the meaning could ambiguous.
This is a vacuous definition because it doesn't specify what is meant by "variable" or what it means to be "given a type." This is not nit-picking. It actually matters in the case of Common Lisp. Consider:
(let ((x 1)) (declare (fixnum x)) ...)
X is clearly a variable, but has it been "given a type"? In CL, type specifications are promises to the compiler, not specifications of program semantics. (declare (fixnum x)) means "I, the programmer, promise to write my code in such a way that the value of X will always be a fixnum, and you the compiler are free to assume that I will do this correctly in order to make my code run faster."
On the other hand:
(setf x (make-array 10 :element-type 'fixnum))
In this case the implementation is allowed (though not required) to make an array that can only hold fixnums. So are the array elements variables? And have they been "given a type"?