[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamic vs. static typing



Howard Stearns <stearns@alum.mit.edu> writes:

> OK, how's this:
>
>    "1. Without early spellchecking, the proportion of typos which
>    manifest during later stages rises significantly.
>
>    "2. Often, the nature of those typos isn't identified as clearly
>    during compiling, testing, or runtime as it would be by a
>    spell-checker, so they take longer to track down.
>
> I don't agree when Anton writes 1 and 2 about type
> checking, and I do believe the same unscientific argument about spell
> checking.

Anton's number one is just an observation that bugs that are fixed
early don't have to be fixed later.  Hard to argue that.

I'm less sure about #2.  Even if it is true, I could counter with 
``Often, the nature of the type error isn't identified as clearly
during type checking as it would be by a dynamic test, so they take
longer to track down.''  This is not as absurd as it sounds at first
glance.  Olaf Chitil gives this example:

  reverse [] = []
  reverse (x:xs) = reverse xs ++ x

  last xs = head (reverse xs)
  init = reverse . tail . reverse

  rotateR xs = last xs : init xs

yields this error:

  ERROR (line 7): Type error in application
  *** Expression     : last xs : init xs
  *** Term           : last xs
  *** Type           : [a]
  *** Does not match : a
  *** Because        : unification would give
                       infinite type

It sure looks like a bug in line 7, but the bug is actually in line 2.
  reverse (x:xs) = reverse xs ++ [x]

Now if this were an error discovered at runtime in a dynamically typed
language it would show us that the second argument to the list
concatenation wasn't a list, but rather a list element.  The error
would be discovered right in the erring routine.