[bitc-dev] Variable Arity Functions?
David Hopwood
david.nospam.hopwood at blueyonder.co.uk
Fri Feb 17 21:30:23 EST 2006
Jonathan S. Shapiro wrote:
> On Wed, 2006-02-15 at 12:58 -0800, Greg Buchholz wrote:
>
>> Will BitC have variable arity functions? If so, how does it work
>>with the static type system?
>
> We do not plan to support variable arity procedures for the forseeable
> future, because Oleg's trick (which is clever, and we had also spotted
> it) doesn't interact well with unboxed argument types that are passed by
> value (issue: drives a need for polyinstantiation of the receiving
> function).
>
> The following is just to explain what we did consider for archival
> purposes:
>
> Depending on the rule for argument consing at the apply site, there is a
> straightforward way to handle variadic arguments. Consider an
> application:
>
> (a b c ... y z)
>
> at one point, we had in mind that the rule would be "pair consing" --
> that is, that an application of the form above would be interpreted as
>
> (a (pair b (pair c ( ... (pair y z)))))
Or (a (pair b (pair c ( ... (pair y (pair z nil))))), which allows the
arity zero case to be neatly expressed as (a nil).
> Note that this has the effect of matching the C calling convention's
> representation on the stack (which was important to us) while resolving
> what to do with the "extra" arguments. It also satisfies type checking
> pretty easily, but it creates a problem:
>
> Given a procedure
>
> (define (f x y:'a) ...)
>
> we are left with the problem that there is no useful way to actually
> pattern match the last argument. Either the type doesn't matter
> (therefore remains an alpha type) or the type is actually interpreted by
> the procedure f (therefore gets assigned some concrete type). In order
> to really deal with variadic procedures, you really do need to introduce
> something like type classes,
Or a Dynamic type:
<http://citeseer.ist.psu.edu/abadi89dynamic.html>
<http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Dynamic.html>
--
David Hopwood <david.nospam.hopwood at blueyonder.co.uk>
More information about the bitc-dev
mailing list