On Tue, Mar 22, 2011 at 7:34 PM, William ML Leslie <
[email protected]> wrote:

> On 22 March 2011 16:33, Jonathan S. Shapiro <[email protected]> wrote:
> > The problem is that even when it is subject to lifetime safety, and even
> > when we consider only the single-threaded case, an init-only field is not
> > immutable.In order for the output of length() to be stable it needs to be
> > immutable.
>
> Could you please elaborate on the issue here?
>

struct S
is
  const i : int32
  const next nullable S

boxed struct Container
is
  mutable s : S;

def S_length(s : S)
in
   case tmp = s in
   null => 0:int32
   otherwise => 1 + S_length(s.next);

def f()
in
  let container = Container(S(5, null))
      chain = S(4, container.s)
      len = S_length(chain)
  in
     container.next = S(6,S(7,null))
     ...

Note that by the point of the "..." , the length calculated for the chain is
no longer accurate. Even though the "next" field of S is init-only, the
value of S in its entirety can be overwritten, with the consequence that the
threading of the chain has been altered.

Among other consequences, this means that in a language having init-only
fields and inner-references, a structure consisting exclusively of init-only
fields is not necessarily pure...

shap
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to