About type inference for ruby

Hi gurus and nubys,

I’m going to put some memes toghether running away in few minutes, to
see what the community thinks.

I just run across this paper[1] from latest PyCon
that explains a way to compile Python to actually efficient C++
using automatic type inference.

I remember matz and others were someway interested in Type/interface
inference, (see this[2] and this[3])
and I, FWIW, would love to see type inference in ruby.

It seem that in the thread referenced by [3] matz pointed out that
stuff like this:

def whatiwould(x, flags)
if flags
x = Regex.new(x.join("|"))
end
x.match(@str)
end

would be actually too hard to analyze for interface/duck signature
inference.

And this relates to blogging from PragDave[4] and Chad Fowler[5]
I which appears the interesting meme that “we don’t want to check
variable usage anytime, we would just check that once a variable has a
type, it does not change substantially”.

Actually I believe too, that you don’t need and should not do
x=12
x=‘str’

Would it make sense to have a flag to say to the interpreter “raise an
exception if this variable gets a new assignment” and then do type
inference?

[1]
http://www.python.org/pycon/dc2004/papers/1/paper.pdf
[2]
http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb/ruby/ruby-talk/1437?1215-1527+split-mode-vertical
[3]
that’s a huge thread…
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/85890
[4]
http://www.pragprog.com/pragdave/Tech/Ruby/LazyType.rdoc
[5]
http://www.chadfowler.com/index.cgi/Computing/Programming/Ruby/TypeWatching.rdoc,v

something I use a lot:
a, b, c, d = ARGV
b = b.to_i

or:
print "What’s your favorite number? "
if (num = gets): num = num.to_i end

or:
print "Enter a date: "
if (date = gets): date = Date.parse date

I find it incredibly useful that you can assign differently typed data
to the same variable throughout it’s lifetime. just reusing a variable?
no, that’s bad programming. But replacing it’s data with the same data,
just in a different form? I think that’s okay, myself.

just my 2¢

–Mark

···

On Mar 25, 2004, at 2:54 AM, gabriele renzi wrote:

Actually I believe too, that you don’t need and should not do
x=12
x=‘str’