From: Trevor Andrade Date: 2005-01-09T08:26:56+09:00 Subject: Re: Type inference in ruby In this case I did not mean redefine integers and integer addition I meant define in the first place. What I was trying to say is that if you had no built in construct in Ruby of integers then there would be absolutely no way in which to define integers or integer addition in Ruby. You would have to make a c extension to the language. Of course it is possible to redefine integers but that is not what I was talking about. What I was originally trying to get at is that there are only 2 things you do in Ruby 1) send messages to objects 2) Perform built in operations on built on things like integers and strings. In 1) you are not really doing anything instead you are sending messages to objects and telling them to do things. In 2) you are doing something like adding integers, concatenating strings, displaying output, getting input etc. Type checking for 1) involves checking if an object can accept a certain kind of message. Type checking for 2) is more involved and depends on the built-in types themselves, like for instance the fact that you can't add a string to an integer although you can add a float to an integer. Even for 2) type inference is still possible because there are only a finite number of built in constructs and their properties are known. Of course if you add in new c extensions to the language then these cannot be checked. However I don't think type checking has to be exhaustive or strong. -----Original Message----- From: Alexander Kellett [mailto:ruby-lists@lypanov.net] Sent: Saturday, January 08, 2005 5:26 PM To: ruby-talk ML Subject: Re: Type inference in ruby On Jan 8, 2005, at 9:28 PM, Trevor Andrade wrote: > You cannot define how to add integers in Ruby and in fact you cannot > even define > integers themselves. Integers are low level constructs that must be > built > into the language. [snip] its possible to redefine integer additions in ruby. however yes you're correct in saying that its not possible to redefine the integer constructor. (tho i'm working on making that possible ;)) > There is only one thing wrong with type inference and that is that new > methods can be defined at runtime in Ruby which means it is possible > that an > object does not know how to respond at compile time to a message but > it does > know how to respond at runtime. However I think this scenario happens > very > rarely and if it was happening the programmer could just turn off type > inference. i think personally that test suites should guide typing metadata. if a testcase only has a test for a single data type. then the assumption can be made that the type itself is required. if however it has a test for two different data types each of which have a given method, which happens to be part of an included module, to ease test case writing it should be possible via comment hints to show the inferrer / document-type-metadata-hinter that it is duck typed not static typed. Alex