Separation of Typing Concerns
Separation of Concerns is one of the principle concepts of Software Engineering. The Typing Concern can be thought as a sub-topic of Aspect-oriented programming (AOP). It considers types as crosscutting, tangling artifacts over a set of source programs.
In Duby, it introduces a syntax for doing type decoration for the original untyped programs. This page discusses a new way to separate types as a modular unit, called a type sheet, to keep the original programs unchanged, and possible to have type information for each method declaration etc. (join points in term of AOP).
Example of the current Duby code:
class Recursive
def self.ack(m, n)
{m => :int, n => :int, :return => :int}
if m == 0 then
n + 1
elsif n == 0
ack(m - 1, 1)
else
ack(m - 1, ack(m, n - 1))
end
end
# ... 3 more methods go here
end
Line {m => :int, n => :int, :return => :int} is a type decoration. We can write a Duby type sheet as the following:
# main.dts - Duby Type Sheet
class Recursive
ack { m => :int, n => :int, :return => int }
fib { n => :int, return => :int }
tak { x => :int, y => :int, z => :int, :return => :int }
main { args => :string[] }
end
So that we can remove the type decoration from the above Duby class. Then the Duby compiler would read .dts files and use type information to decorate matched classes at compile-time.
Pointcut Language for Type Sheet
As typing concern shares the concept of AOP, thus it would be great to have a pointcut language to describe elements in a type sheet. From the above example, we found that 3 methods have all arguments as 'int'. So we could write:
# main.dts - Duby Type Sheet
class Recursive
ack, fib, tak { * => :int }
main { args => :string[] }
end





