Signature Typing

SignatureTyping, which could possibly also be known as StaticDuckTyping? or StaticPolymorphism, statically checks an object's signature, rather than its actual type in the typechecking phase of compilation. A really good SignatureTyping language would infer from how you use the object what signature it has, allowing you to write code that looks like python, but is actually checked at compile time. The advantage to SignatureTyping is that you can have abstract signatures, like iterable, callable, or can-be-added-to-an-integer, rather than actual types, like ExternalIterator, FunctorObject, or Integer. The advantages of this are:

    def apply(f : Callable, lst : Iterable):
         y as Duck = None
         lst.ToInternalIterator?.each => x:
              y = f(y, x) if y is not None else x
    return y
    class SomeClass?():
         def call(x, y):
              return x + y
    apply(SomeClass?(), [1, 2, 3]) # => 6
    apply(SomeClass?(), [(1, 2), (3, 4), (5, 6)]) # => (1, 2, 3, 4, 5, 6)
    apply((lambda x, y: print x; print y; y), (1, 2, 3, 4)) 
    # 1
    # 2
    # 2
    # 3
    # 3
    # 4
    # => 4


EditText of this page (last edited February 27, 2010) or FindPage with title or text search