If you can show me a 'type' that cannot be assigned to
a
in the same scope then I would be most interested to know, I haven't
found one yet.
As other people have said, you've just pointed out the difference
between static typing and dynamic typing -- and how the former types
variables (or "names") and the latter types objects. I just have a few
things to add to your post and others.
First, from some point of view, you're correct. From a type theory point
of view "dynamically typed" is an oxymoron, because *by definition*
(from this point of view) types are a property of variables (and
expressions). For example, Ben Pierce says (in "Types and Programming
Languages"):
The word "static" is sometimes added explicitly...to distinguish
the sorts of compile-time analyses we are considering here from the
dynamic or latent typing found in languages such as Scheme, where
run-time type tags are used to distinguish different kinds of
structures in the heap. Terms like "dynamically typed" are arguably
misnomers and should probably be replaced by "dynamically checked,"
but the usage is standard.
(And the usage is standard because it's just really useful to be able to
say "dynamically-typed" instead of "uni-typed with runtime checks of
things that act like types". (I don't think Pierce's "dynamically
checked" is specific enough.
)
Second, this concept isn't *so* unfamiliar to you. If I give you the
following Java code:
void foo(Object o) { ... }
and ask what type 'o' is, there are kind of two answers. The first is
that 'o' is an 'Object'. But you can't make an Object -- that's an
abstract class. (IIRC. If it's not then just bear with me; you get the
idea.
) So from a strictly static type-theory point of view, 'foo' is
unusable because it takes a type which you can never create. But of
course that's not the case, because in actual Java 'o' has some dynamic
type which is a subclass of 'Object'.
Though I'm sure this statement will be *really* popular with this list
</sarcasm>, if it puts your mind at ease a little, you can imagine that
there are no primitive types and Python names all have type 'Object',
but that you can refer to the functions in an object's dynamic type
without explicitly downcasting. (The analogy isn't perfect.)
The classic example of weak typing is concatenation of strings and
numbers, e.g. ("abc" + 123). Weakly typed languages like JavaScript
will implicitly coerce the number to a string and perform the
concatenation. Strongly typed languages like Python will raise a
TypeError instead.
I would also say don't get *too* caught up in categorizing everything
into "strong" and "weak"; that's a spectrum, and where things fall is a
lot more interesting than just "here or there". Really it's even more
complex than just a linear spectrum -- Language A can be stronger than
Language B in one respect but weaker in another.
In particular, it's possible to have rather stronger typing than Python
(especially with respect to Booleans, but in some other respects as well).
Evan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla -
http://enigmail.mozdev.org/
iQEVAwUBUDUtCAOzoR8eZTzgAQI5fQf+JGJGss3/zHa80wTS64z5suZAzdPJ2DKx
o9OqXuA1Z+eL7xe4bztFVelEKM2cycAdZXuGX1oURzlK8TPWygCSm0a9PmS8zXxG
1LTCUCJSDon9iyUFmX3GJJf+bK3cQVXQj+ZYKHWxwI70AV6h9SgC4MFhamY0Itm/
NuUPn5cjiYh2j5C6klYYyQXFHIH2Eqh8PhRTrHnXQlhQmCQNvbMPvxNXB2Xo8sFT
mlPXCvl/jA1GxDhmdVCNjuwMqrsu3gqu6wHFdGPO89+JV9epwH+41tM1vo/a8IEf
UYuLtV/SwRori5ZiBkb/0SZhBrCJc7wAC6LxC3cl4VOefTTQE9PBRw==
=zsXj
-----END PGP SIGNATURE-----