Talk:Typing

From HaskellWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The article contains this:

  • Weak typing: There are only few distinguished types and maybe type synonyms for several types. E.g. C uses integer numbers for booleans, integers, characters, bit sets and enumerations.
  • Strong typing: Fine grained set of types like in Ada, Wirthian languages (Pascal, Modula-2), Eiffel

This is not my understanding of strong and weak typing at all. I would like to replace it with:

  • Weak typing: Objects have types, but are implicitly converted to other types when the context demands it. For example, Perl, PHP and JavaScript are all languages in which "1" can be used in more or less any context that 1 can.
  • Strong typing: Objects have types, and there are no implicit conversions (although overloading may be used to simulate them), so using an object in the wrong context is an error. In Python, indexing an array with a string or float throws a TypeError exception; in Haskell it will fail at compile time.

However I lack any real authority to back up this definition. Comments appreciated.

I actually also find the definition of static/dynamic typing unsatisfactory. I'm not sure in this case what I would use instead, but IMO it's something about whether type errors arise according to the structure of a program, or according to its execution, e.g. the following Python is not a type error:

if False:
    x = None + 1

This seems to be a more denotational definition than the somewhat arbitrary runtime/compile-time distinction.

--benmachine 17:25, 7 May 2012 (UTC)