From: "Jörg W Mittag" Date: 2009-05-15T10:05:02+09:00 Subject: Re: Any current preprocessor/Ruby language add-ons? Caleb Clausen wrote: > On 5/12/09, C. Dagnon wrote: >> I'm curious what project people are working on with respect to the Ruby >> language, compiler, or any preprocessors. Specifically I want to use >> file- or project-wide directives (as in VB where new variables require >> explicit declarations), and I want to add preconditions, postconditions, >> type checking, side effects, and tests/behaviour assertions within the >> code files along with associated automated analysis. > There have been a number of efforts to add static typing (-ish) > features to ruby. The most recent is Diamondback Ruby; an announcement > for it was posted here a couple weeks ago. It has some kind of method > annotation special comment for declaring types of arguments, like you > wanted. AFAIU, that's not the primary use case for Diamondback Ruby, though. The intention is that, ideally, DRuby should be able to typecheck *any* existing Ruby code without modifications. The type annotations were primarily added because while DRuby can typecheck Ruby code, it is based on MRI, in which many "Ruby" classes and methods are implemented in C. Since DRuby cannot typecheck those, it needs type annotations. Ironically, type annotations are also needed for Ruby code that implements "static-ish" features by hand, because DRuby cannot statically figure those out. The main examples are methods that just take an *args array and then implement method overloading by hand (e.g. String#[]). But I *think* you can also use type annotations the way you describe, by basically using a "double-entry bookkeeping" scheme similar to Haskell: DRuby infers the types from the code, but then it compares them to the annotation and checks if they match. A nice property of DRuby type annotations is that their syntax is derived from the semi-formal unofficial type syntax that is *already* widely used inside the core and stdlib RDocs. jwm