From: Austin Ziegler Date: 2005-01-10T03:30:28+09:00 Subject: Re: Type inference in ruby On Sun, 9 Jan 2005 03:54:13 +0900, Trevor Andrade wrote: > Hello all, > > I was wondering whether it would be possible to have a type > inference system in ruby. My question was asked before > > by gabriele renzi but it never received much of a response. This > system might try to figure out whether you are writing code with > some obvious errors. There has been a > project on this for > smalltalk. For instance if you have a function like the following > > def foo(object) > return object.call(9, 7, 3) > end > > couldn't the type system figure out that object must respond to > the call command and thus eliminate an error like: > > foo(5) I'm not sure what you're trying to say here; are you wanting the parser to detect errors like this? I'm not sure that's the right place; sure Fixnum doesn't have a virtual class, but you can do this: class Fixnum def call(*args) puts args.join("|") end end This then totally screws up your type inference. There's no way to be certain -- at parsing time -- that a particular call would be invalid. > I guess I am also wondering about a lot of other things like why > do you need multiple assignment in Ruby? There doesn't seem to be > any need for it since you can just modify an object by sending it > a message eg x = x + 1 is the same as x.+(1). Multiple assignment? Do you mean: x, y = y, x Or do you mean specifically: x = x + 1 As far as your statement is concerned, x = x + 1 is NOT the same as: x.+(1) It's the same as: x = x.+(1) There is a distinct and important difference here. In Ruby -- the language proper -- type inference won't really help, at least IMO. In an interpreter or compiler for Ruby, it could make a difference. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca