5 ms·
> They are typed. Weakly/dynamically typed. Unityped, as in, they have only one type. You can assign any type to any variable, so all values have a single type
by naasking 8y ago
> They are typed. Weakly/dynamically typed.
Unityped, as in, they have only one type. You can assign any type to any variable, so all values have a single type.
> Also, division by zero is an runtime operation error, it is not really a type error. The division operation doesn't fail because it violated the type system, it fails because you can't mathematically divide by zero.
That is a type error in some type systems. The general notion of a type is a logical proposition. "Non-zero number" is a proposition and so you can represent this with types. The type of division is then `Num -> (Num != 0) -> Num`.
> Dynamic languages are untyped languages like javascript and racket.
This is not true. All languages are typed, either with rich types, or they are unityped (like the lambda calculus or JS).
Machine language is typed, and the fundamental types are (roughly) word and double. These are the registers of machine language, which you can roughly think of as variables in programming languages.
- int_19h 8y agoValues in JS still have different types (as evidenced by their different behavior). Variables could all be argued to have one type in JS, which is the root type (which everything else subtypes). So no, JS is still not untyped, merely dynamically typed. An example of a language that also has only one data type for value would be something like Tcl, where the only type is a string - and everything else is just an optimized way to store certain kinds of strings, that could be removed without affecting semantics of any program.
- kazinator 8y agoThey could be argued, but that would be wrong. If we define a variable, give it the value 42 and then never change it over the lifetime of the image, then that variable's type is integer. Or, even more specifically, its type is the set { 42 }. It may be the case that no such thing is actually analyzed and the implementation always retains the potential to reassign that variable; that doesn't change the mathematical fact that the set of values which that variable is fixed. That the implementation is not interested in examining the type of a variable (let alone checking for consistency with the rest of the program) shouldn't be mistaken for the absence of type. There is a mathematical fact about the program that isn't constrained by the quality and depth of its implementation.
- anon_d 8y agoJavascript is Unityped. In Haskell/ML, you would define the type of Javascript objects by doing something like this: data JSObj = Num Double | Str String | Obj (Hashtable String JSObj) | True | False | Nil | Undefined
- naasking 8y ago> Values in JS still have different types (as evidenced by their different behavior). Behaviour is based on values, not types. 1+2 will print out a different value than 1+1, but these expressions have the same type (typically). > So no, JS is still not untyped, merely dynamically typed. I said JS was unityped, not untyped.
- int_19h 8y agoValues also have types, it's not something that's exclusive to expressions and bindings.
- kazinator 8y agoThat is simply not so. Values and variables are not the same thing. Just because variables do not have a type (can potentially hold any value) doesn't mean that values have no type. Furthermore, variables potentially holding any value doesn't mean they have no type. It is just a potential. A variable effectively has that type which is actually put into it. If a given variable is always either a string or nil, then that's what it's type is; the sum type of null (the type that contains nil) and the string type. It may be the case that in a given language implementation, this fact about the variable is not calculated; but it's still a fact. Neglecting to analyze the types of variables (and other nodes in the program) is an implementation quality/depth choice, not a kind of type system design.
- naasking 8y ago> Just because variables do not have a type (can potentially hold any value) doesn't mean that values have no type. Furthermore, variables potentially holding any value doesn't mean they have no type. I said they have one type, I didn't say they have no type.
- kazinator 8y agoThat basically means the same thing. "Typeless dynamic language" and "all variables and object slots having one type" are essentially the same claim: that the bindings or storage locations are all indistinguishable and can take on any value. (If they have one type, what is that type? And can values be of that type?)
- igouy 8y ago> Unityped, as in, they have only one type. If there are no distinguishable properties ("one type") then untyped vs unityped seems a distinction without a difference.
- naasking 8y agoUpon further thought, there's probably a useful distinction to be made here. Let's take the classical untyped lambda calculus as a canonical untyped language. Every value is a lambda, so there is clearly only one type, and no deeper structure at play. Now contrast with something like Scheme or JS. Clearly there is richer underlying structure than mere lambdas, but since every value is still interchangeable (a global sum type) I think this suggests a "unityped" label as a meaningful distinction from the untyped case. So I would amend my original comment to move the lambda calculus out of unityped and into untyped, and possibly Tcl as well since everything is conceptually a string there.
- igouy 8y agoLet's take BCPL — 'The major difference between BCPL and ALGOL is that all ALGOL variables are declared with data-types (integer, real, boolean, string, array, procedure, label, pointer, etc.), whereas all BCPL variables have the same data-type: a 16-bit number. In ALGOL, the meaning of an expression is dependent both on its context and on the data-types of the entities involved, and only expressions with certain data-types may appear in a given context. In BCPL, any expression may be used in any context; the context alone determines how the 16-bit value of the expression is interpreted. BCPL never checks that a value is "appropriate" for use in a given way.' http://www.bitsavers.org/pdf/xerox/alto/bcpl/BCPL_Reference_Manual_Sep79.pdf http://www.bitsavers.org/pdf/xerox/alto/bcpl/BCPL_Reference_... ( I haven't been able to figure out what happens on divide-by-zero: The division operator / yields the correct result if E1 is divisible by E2; it is otherwise implementation dependent but the rounding error is never greater than 1. https://www.bell-labs.com/usr/dmr/www/bcpl.pdf https://www.bell-labs.com/usr/dmr/www/bcpl.pdf )
- igouy 8y agoSurely the meaningful distinction between BCPL and Scheme is that BCPL is not type safe and Scheme is type safe.
- YouAreGreat 8y ago> All languages are typed, either with rich types, or they are unityped Almost all languages. There is one language that can be typed without a type, the empty language. Since the empty language contains no programs, it follows that "Untyped Programs Don't Exist".