[bitc-dev] on mutable types
Jonathan S. Shapiro
shap at eros-os.org
Sat May 20 06:35:40 EDT 2006
On Sat, 2006-05-20 at 01:27 +0100, Sam Mason wrote:
> Hi,
>
> It's probably a bit late for this, but I'm a bit confused by the "mutable"
> keyword. It appears to do two things, firstly it allows the contents
> of a variable to be changed at runtime. Secondly, in providing this
> mutability an extra level of indirection is introduced -- it is this that
> surprises me. I would expect it function more like the complement of the
> "const" keyword in C.
No extra level of indirection is introduced. The REF keyword in SML
*does* introduce such a level of indirection. One of the major changes
in BitC -- and a significant departure from the type system of SML -- is
that we do *not* do this.
Can you identify the part of the specification that leads to this
confusion? I would like to correct it.
> If I did have a C library that accepted a double[] as a parameter, what
> would it's type be in BitC?
This cannot be written in BitC, because we don't have literal classes.
The problem here is that you are actually passing the address of an
array of unspecified length, and it is not generally safe to capture
that address.
For an array of specific size, you could write:
(define (f arg:(array double 10)) ...)
To accept an arbitrary sized sequence type, it would need to be a
vector:
(define (f arg:(vector double)) ...)
shap
More information about the bitc-dev
mailing list