96 points · by tosh · 9y ago · 56 comments
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"?
> 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.
"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.
Physics on the other hand very much has types, the unit to type correspondence is dopetastic.
Lately there's been a resurgence in foundations because of what new foundations like Homotopy Type Theory bring to the table. Funny how something as basic as equality can be revisited time and time again for thousands of years!
But I preffer to keep that stuff in, even when doing pretty abstract stuff. Essentially because I wanted the type annotations. For example my favorite convention for the Minkowski metric is:
[c^2 0 0 0]
[ 0 -1 0 0]
[ 0 0 -1 0]
[ 0 0 0 -1]
That way your vectors are just $(t, x, y, z)$, where $t$ has units of time and the rest of space. Your covectors do come out oddly as $(c^2t, -x, -y, -z)$, but that's what makes them covectors.Mathematics is often expressed in language, That language us usually a mix of a human natural language English/French/German/etc plus symbolic extensions, and that is very poorly typed.
In the recent failed proof of P!=NP, the flaw was a type error:
https://cstheory.stackexchange.com/questions/38803/is-norber...
Type errors are rather common in math proofs that end up retracted.
But it's hard to call them type errors, because it's not like a computer program where the typechecker detected the collision or failed in some way: the proofs make very little mention of types at all, and it's up to the readers to apply a type-system from their own heads.
The link you gave does not support this statement.
For example suppose a geometer explains something to another geometer just by drawing diagrams with no verbal or textual annotation. You can plausibly claim that "geometry diagrams" are a language, but now you are defining language so broadly that the term is almost useless.
Mathematics is largely based on set theory, so every element has a set it belongs to, and every function has a source-set (domain) and a target-set (co-domain). Mathematicians are very careful to always qualify the encompassing sets, domains and co-domains. You would always write:
* Let x \in X be a point in Space. * Let f:A->B be a fuction with ceratin properties.
This is even more pronounced in Category theory, which invaded algebra and geometry quite heavily. Where the only thing you know about a function is it's domain, codomain and how it composes.
So, yes. Mathematics on a practical level is _very_ type aware.
And it also prevents you from doing stupid stuff: f:A->B, g:A->C, can't be composed, so f(g(x)) is a "type error".
This is generally on purpose, to avoid making explicit things that are obvious, but as someone developing and using statically typed languages, reading Math papers is often quite frustrating.
As others have mentioned, Mathematics isn't really a language. It's at the very least absolutely certainly not one language. Certain parts of Mathematics use a typed language. Certain parts rely on other kinds of containment properties which serve nicely as types.
Finally, generally, math is very interested in being completely clear the properties of objects and very interested in speaking abstractly, so even if the language of use is untyped the logic is often very rigorous around typing.
Above it all, perhaps, is the idea that mathematics is concerned with proof and proofs may contain reference to the properties being discussed---metamathematical ideas pervade normal mathematical thought. This means that even absent of types the content of a mathematical utterance is often going to explicitly posit, discuss, and prove properties similar to type propositions.
No, but static type hinting is strongly encouraged. If I say in my paper that "x" is a vector, if I later use "x" to mean a scalar it would cause tremendous cognitive dissonance and confusion for the reader. There is no compiler error, in that the information can still be read and understood. It is just much more difficult.
Mathematical notation is also aggressively polymorphic. The expression "f x" can have wildly different meanings depending on what "f" and "x" are.
For a more balanced discussion, see: https://www.infoq.com/presentations/dynamic-static-typing
And I think you'll find that Gilad Bracha is a more informed critic of reliance on static type checking.