I am having strange thoughts today. This goes under the heading of
"things I want to capture, but we should not contemplate for the
language".
Today, BitC will not infer structure types. If you write a procedure:
(define (f x) x.someField)
BitC will not attempt to infer the type of 'x', even if there is only
one structure type in scope that has a field named someField.
In Coyotos, we have structures like Process whose first element is
ObjectHeader (poor man's single inheritance). While we don't have it in
BitC today, it would be straightforward to add something like:
(defstruct Process (extends ObjectHeader)
... fields ...)
and it might even be possible to deal with the inference issue of
recognizing that all Processes are ObjectHeaders.
What I realized today is that this is not actually necessary.
We can model field assignment and access as (respectively) calls to
[implicit] getFoo() and setFoo() methods of the containing structure[*].
If we do this, then we can handle structure polymorphism through type
classes. In the example function F above, we can automatically re-write
F as:
(forall ((__hasGetsomeField 'a 'b))
(define (f x:'a) x.someField:'b))
where 'hasGetsomeField' is an implicitly-introduced type class. The idea
is that simply *defining* a structure that has a field "someField"
should (a) define the type class __hasGetsomeField if it is not already
defined, and (b) show that the new structure is a member by providing
the obvious accessor and mutator functions.
This provides structure genericity through the framework of type
classes.
Now look again at the "Process is an extension of ObjectHeader" case. In
this case we are able to notice that all actual instantiations of F have
identical code (because they are actually accessing the same field at
the same offset with the same type) and use a single implementation.
[*] There is a problem with this, which is that the get() and set()
methods cannot currently be expressed within the language. The issue is
that we need a notion of a non-escaping reference. Specifically, we need
a mechanism that allows us to write a procedure like:
(define (init-foo x:(by-reference (mutable foo))
(set! foo.field1 initial-value)
...)
In contrast to a general STACK-REF type, I think that this can be
introduced safely.
shap
--
Jonathan S. Shapiro, Ph.D.
Managing Director
The EROS Group, LLC
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev