[Prev][Next][Index][Thread]

Re: function signature type checking



Kim Barrett <kab@camellia.org> writes:
> limited(<function>, ...) seems like the right approach.  However, I think
> there are people who would dispute that "quite easily".  

Things might be easier if signatures are not considered to be functions, since
they cannot be executed after all.

This is the kind of thing I would like to be able to do:

  define signature <accumulator> (sum :: <number>; n :: <number>)
    => result :: <number>;

  define method accumulate (a :: <accumulator>; c :: <collection>)
      => result :: <number>
    let sum :: <number> = 0;
    reduce(a, sum, c);
  end method;

  define constant f = method (sum :: <number>; n :: <number>)
      => result :: <number>;
    sum + n;
  end method;

  accumulate(f, #(1, 2, 3));

These relations would hold:

  instance?(f, <function>)
  instance?(f, <accumulator>)
  instance?(<accumulator>, <signature>)

The type "wierdness" of signatures vs functions comes about with:

  instance?(<accumulator>, <function>) == #f
  subtype?(<accumulator>, <function>) == #f
  subtype?(<signature>, <function>) == #f

The supertype of <signature> is anyone's guess.

This kind of thing seems (in my ignorance) to be easy to do, mainly because
signature matching is an ability already in the compiler. I don't know if there
are type classification "gotchas" that such a signature scheme would cause.

-- 
Cheers,                                        The Rhythm is around me,
                                               The Rhythm has control.
Ray Blaak                                      The Rhythm is inside me,
blaak@telus.net                                The Rhythm has my soul.



Follow-Ups: References: