From: Robert Feldt Date: 2001-12-12T09:09:12+09:00 Subject: [ruby-talk:28292] Re: The benefits of dynamic typing? On Wed, 12 Dec 2001, Harry Ohlsen wrote: > > Something like > > > > class T > > type_hint Integer, :m, Integer, Integer > > def m(a,b) > > a+b > > end > > end > > I assume what this means is that the method is intended to return > Integer, and the arguments are both intended to be Integer, hence the VM > is being asked to do appropriate conversions, if possible, if the actual > arguments passed (or the return value) don't match? > No, actually I had something else in mind but you can easily add the semantics you want. I guess you can even use this scheme to write "overloaded" operators in this C++-style class MyClass type_hint MyClass, :m, Integer def m(anInt) #... end type_hint MyClass, :m, Float def m(aFloat) #... end end but implementation is left as an excersise for the reader... :-) (Basically type_hint has to rename any-previous incarnations of the method and then add a dispatcher choosing the actual method based on the types...) I'm not saying its good, just doable! What I had in mind was type annotations to make optimizations possible when you doing a compiler. Regards, Robert