Jonathan S. Shapiro wrote:
> Quite a while back, we discussed the following:
>
> I want to have a pair whose first element is a reference, and whose
> second element is a procedure accepting that reference. Naively this is
> something like:
>
> (pair (ref 'a) (fn (ref 'a) ())
>
> But what I want to express is that we don't care what the 'a is as long
> as it matches inside the pair. That is, my intention is that I should be
> able to specify a mutable slot within a structure of this type, and I
> should be able to first assign into this slot a pair of type
>
> (pair (ref char) (fn (ref char) ())
>
> and then later assign a second pair of type:
>
> (pair (ref int) (fn (ref int) ())
This is not expressible in present BitC. For this, we need existential
types which can `hide' the type variable within the object.
That is, in present BitC, we can only have types of the form
(defstruct (pr1 'a) fst: (ref 'a) snd:(fn (ref 'a) ()))
Under this scheme, the two values
(pr1 (dup #t) (lambda (x) ())
(pr1 (dup #\a) (lambda (x) ())
will have _incompatible_ types
(pr1 (dup #t) (lambda (x) ()) : (pr1 bool)
(pr1 (dup #\a) (lambda (x) ()) : (pr1 char)
However, if we have existential types, we could write something like
(defstruct pr2 (forall ('a)) fst: (ref 'a) snd:(fn (ref 'a) ()))
where 'a is held abstract from the outside perspective, unless it is
"opened" through certain match construct.
Now, the two values will have the same type
(pr2 (dup #t) (lambda (x) ()) : pr2
(pr2 (dup #\a) (lambda (x) ()) : pr2
and can be used interchangeably (in this case, to overwrite a structure
field).
Swaroop.
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev