I have a few questions about the inference of mutability. For this
discussion, please ignore open issue of whether mutability coercion must
be deep or shallow.
Consider:
(defunion t:val T)
i) Now, if I write:
(define (f x) (let ((y:(mutable t) x)) ())
Is the type of the function:
f: (fn (mutable t) ()) or just
f: (fn (t) ())
I am guessing the latter, but If we see:
(define (f x) (let ((y:(mutable t) x))
(set! x T) ())
The type of f must be (fn (mutable t) ())
This is a little weird because, at the step
(let ((y:(mutable t) x)) ... )
If we infer the type of x as t, then we must perform a "promotion" to
(mutable t) later.
But if we have seen:
(define (f x:t) (let ((y x))
(set! x T) ())
Now, x id of type t and no promotion should occur. That is, the type of
x in the previous example is somewhat tentative till the end of the
function, but an explicit qualification made it permanent?
ii) Also, can a function ever return a mutable type? If I write:
(define (f x:(mutable T)) x)
Is the type of f (fn (mutable t) t) or (fn (mutable t) (mutable t))
The former would mean that one can never write:
(set! (f T) T)
but can write:
(let ((y:(mutable t) (f T)))
(set! y y))
iii) The issue we came across for literals wrt mutability is actually
true for all constructors in general. If I write:
(define x:(mutable t) T)
then, x is a mutable value of type (mutable t) constructed from T the
constructor for type t.
Swaroop.
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev