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

Re: dynamic vs. static typing

On Wed, 26 Nov 2003 14:06:06 -0500
"Anton van Straaten" <anton@appsolutions.com> wrote:

> I seriously do believe that for these type systems or variants of them
> to gain wider adoption, issues like these will have to be better
> addressed.(Are there any ST functional languages that do much better
> in these areas?)

[assuming "these areas" include better error reporting]

There are several moves to address this issue.

There is Helium, an "educational" version of Haskell, with a strong
emphasis on helpful error messages.

Chameleon has a "Type Debugger", which can be used with Haskell as well,
that allows better and interactive analysis of type errors.

There's "Type Error Slicing" which reports all parts of the program that
are directly involved in the error.

Finally, it's considered good practice in Haskell to provide type
annotations for top-level functions.  For example, a type annotation on
reverse from Joe's example, gives the following (with GHC, I don't have
Hugs installed): 
Cannot unify the type-signature variable `a' with type `[a1]'
	Expected type: [a]
	Inferred type: a
In the second argument of `(++)', namely `x'
In the definition of `reverse':
	reverse (x : xs) = (reverse xs) ++ x

Or starting from the error, it says something is wrong with last so we
ask what last's type is, it's [[a]] -> a which is obviously wrong, you
could provide a type annotation to last which will say reverse is wrong,
but since head is unlikely to be wrong, we see it's reverse, we ask it's
type and get [[a]] -> [a] which is wrong, and if we don't see the error
yet, we can provide the type of reverse which gives the above type error
which could hardly be more direct.  Note that this
practice also makes it unlikely that Dan's "type error five modules
over" would occur.  At any rate, dynamic typing has the same issues,
I've had two (ultimately) type errors in Smalltalk just recently whose
source wasn't pinpointed in the debugger and which took some time to
track down the true problem.