“Bill Kelly” billk@cts.com wrote in message news:00f201c43872$65c0ae10$6442a8c0@musicbox…
Why does that somehow sound in violation of at least one of the
laws of thermodynamics? …

It requires a lot of effort on the part of the person implementing the
type-checking system, but none on the part of the users.
As Gabriele said in response to Gavin’s question:
So, Sean, what kind of type checking would you like to see in Ruby?
And what kind of type checking do you thikn is possible?
static automagic interface inference :))
This is exactly correct. This is the sort of type checking that some
languages, like Haskell, have. Of course, in Haskell you can get much
more strict, because Haskell doesn’t have Objects, and functions are
strongly typed. The best you can do in Ruby is guess at the
duck-typing and ignore issues of self-modifying code. In Ruby, type
checking must be optional, and be considered a debugging tool rather
than a language feature; I doubt if Ruby can ever be made strongly
typed without removing some other language features.
In any case, consider the following code:
def my_func( my_arg )
my_arg.each { |x| x.add( 1 ) }
end
A type checker can determine a number of things from this:
- my_arg must implement each()
- The objects iterated over by each() must all implement add()
- The add() method of these objects must accept Fixnums
A deep type checker could verify that both of these conditions hold,
and could detect errors elsewhere in the code such as:
my_func( 1 )
my_func( %w{ hello world } )
This could all be done outside of the Ruby VM, of course; implementing
this would, IMO, be a large, possibly complicated, job. However, it
could be done, and could check most Ruby objects in
non-self-modifying code.
Again, I don’t recommend that this be default Ruby behavior. I’d love
to see it tied to the “-c” argument, so that, when testing, one could
run a type check test.
I wouldn’t say that mistyping based errors are rare in Ruby, so
something like this would be useful. To be honest, though, it is too
large a job for me to undertake – without getting paid for it – and
would probably best be done within the Ruby VM where we have access to
the parse tree.
— SER