William Djaja Tjokroaminata wrote: > (Sigh), if only I understand lexing and parsing and have more time, I > probably would have started experimenting with "R". At least I will > have this to start > > def (Numeric a) > end > > which is in Ruby equivalent to > > def (a) > raise "type error" unless a.kind_of? Numeric > end > While I certainly don't feel that such things should be a part of Ruby proper, a statically-typed language based on Ruby and Eiffel might be rather interesting. However, rather than a strict class/type association that most languages adhere to, I think it would be more interesting to equate type with *contract*. What I mean is that you could make a contract a first class language construct. For example: contract Enumerable def include?(something) pre # None in this case # Maybe you could include a default implementation here... post result = (!find.nil?) end # etc., etc. def invariant # invariant expressions end end Then a class that supports a particular contract could include it wholesale: class Array include Enumerable end or could declare piecemeal that particular methods adhere to a particular contract: class Array def Enumerable::include?(something) # this ensures that include? adheres to the contract in Enumerable end end With this kind of construct, methods would not necessarily declare a class/type for parameters; instead they could declare that parameters must support a particular contract, /or/ a particular subset of a contract. For example, consider a method that does something with a String: def convert(s: String) # use String methods such as gsub end Now, as some people have pointed out, in most cases we don't really care whether or not the parameter is actually a String, only that it supports some subset of the functionality of a String that we need for our specific purposes. It may be that all we really care about is that the parameter has a gsub method /that conforms to the contract for String/.: def convert(s: String[gsub, other_methods_needed, ...]) # use only methods explicitly mentioned in parameter list end This is what you can't really do in Ruby. You can check to see if an object responds to a particlar message, but you cannot determine whether it supports the semantics that you are assuming...a method name is not sufficient information. This keeps classes and types "loosely coupled". A language based on a construct like this might be able to retain the dynamicity of Ruby with the static safety of Eiffel. Then again, it might also turn out to be a horrible mess. ;-) -- Jason Voegele "We believe that we invent symbols. The truth is that they invent us." -- Gene Wolfe, The Book of the New Sun