Test cases and static typing

Dirk Thierbach dthierbach at gmx.de
Fri Oct 24 14:40:15 EDT 2003


Pascal Costanza <costanza at web.de> wrote:

> As long as I am writing only tests, I don't care. When I am in the mood 
> of writing tests, I want to write as many tests as possible, without 
> having to think about whether my code is acceptable for the static type 
> checker or not.

Then just do it. Write as many tests as you care; when you're ready,
compile them and run the type checker.

Where's the problem? One thing that is certainly missing for Haskell or
OCaml is a good IDE that supports as many styles of programming
as possible, but even with the primitive command line versions at the
moment you can do what you want in this case.

And anyway, this would be a question of the IDE, not of static typing.

>>>The type system might test too many cases.

>> I have never experienced that, because every expression that is valid
>> code will have a proper type.

>> Can you think of an example (not in C++ or Java etc.) where the type
>> system may check too many cases?

> Here is one:
> 
> (defun f (x)
>   (unless (< x 200)
>     (cerror "Type another number"
>             "You have typed a wrong number")
>     (f (read)))
>   (* x 2))

> Look up 
> http://www.lispworks.com/reference/HyperSpec/Body/f_cerror.htm#cerror 
> before complaining.

Done. But I still miss the point. OTOH, Lisp certainly doesn't check
types, so I don't see how a Lisp program can be an example of the
type system checking too many cases. OTOH, this example is tied to
a specific Lisp debugger feature. I think it would be better to give
an example in a statically typed language.

I could probably rewrite the code with an approximation to cerror
(with the restriction that non-local control structures don't 
translate one to one), but even then I don't see why the type system
would test too many cases for this example.

- Dirk






More information about the Python-list mailing list