Python from Wise Guy's Viewpoint

Ed Avis ed at membled.com
Mon Oct 27 18:21:06 EST 2003


Joe Marshall <jrm at ccs.neu.edu> writes:

>Nitpick: You are defining as a program that which passes a static
>type checker.  What would you like to call those constructs that make
>sense to a human and would run correctly despite failing a static
>type check?

In a language such as Haskell, there are no constructs that 'would run
correctly' despite being ill-typed.  If you define

    f :: Int -> Int

then there's no way that f 'would run' if you somehow passed it a
String instead.  I should point out, however, that typically a
function will be defined over a whole class of values, eg

    f :: Eq a => a -> a

so that the function f works with any type that has equality defined.

In Lisp too, there are no programs that 'would run correctly' after
failing type-checking, because a type checker for Lisp would have to
be more liberal (and so potentially less helpful) than one for a
language like Haskell or ML.

The job of a type checker, just like a syntax checker, is to eliminate
programs which do not work.  That's all there is to it.

By narrowing the set of programs which work - that is, introducing
some redundancy into the programming language by increasing the number
of programs which are 'wrong' - you can often save the human
programmer some effort by catching mistakes.

-- 
Ed Avis <ed at membled.com>




More information about the Python-list mailing list