4 ms·
I thought I was talking about the principal of static typing, rather than any language's implementation of it. Back to my original point, if you have tell your
by ianamartin 9y ago
I thought I was talking about the principal of static typing, rather than any language's implementation of it.
Back to my original point, if you have tell your language that 2 is an integer, well, that is a certain kind of issue with that. And if you don't have to tell it that, then there's another issue that happens.
I don't know Haskell or OCaml beyond toy programs, and I'm willing to hear things beyond my knowledge. But as far as I do know, the point doesn't change.
I'm happy to eat my words and learn.
- Sharlin 9y agoThe GP's point was that "good" statically typed languages have type inference and indeed do not need to be told that 2 is an integer and "two" is a string. It is pretty orthogonal to the question of dynamic vs. static typing. In C++: auto i = 2; auto s = "two"; Scala: val i = 2; val s = "two"; C#: var i = 2; var s = "two"; Rust: let i = 2; let s = two; and so on. Note that these are not dynamically typed bindings - you cannot later assign a string to i, or an integer to s. However, these are examples of local type inference where the compiler simply deduces the type of a variable binding based on the type of the bound expression (although Scala and Rust type inference is actually somewhat more general than that). Haskell, on the other hand, has global type inference where the compiler considers the whole program when assigning types to bindings that are not explicitly annotated. However, some arguably useful capabilities of a type system such as subtyping and implicit conversions make global type inference a much more difficult problem to solve.
- falcolas 9y ago> if you have tell your language that 2 is an integer, well, that is a certain kind of issue with that. The question is what size integer - that matters, no matter how much our programs attempt to abstract it away. And the value 2.0 is an integer as well, but no program will consider it to be an integer, instead considering it to be some approximation of the integer value of 2.
- mannykannot 9y agoI do not know of any language in which you have to declare that 2 is an integer. I do know of a few that require you to have stated whether the variable you are assigning it to is to be regarded as an integer or a float. This is not a good example, as it is unreasonably biased towards making explicit typing look like pointless bureaucracy. A better example would be "2". Or the struct / tuple { 2, 2.0, '2', "two" }.
- tome 9y ago> I thought I was talking about the principal of static typing, rather than any language's implementation of it. Then may I suggest expanding your mind by learning about good implementations of static type systems? Any of Haskell, Ocaml or F# would be a good place to start.