Actually, in both cases the list head is mutable but it's target fields and "downstream" cons cells are not. The readonly annotation on the second case *is* transitive, because readonly here is a metaconstructor on the overall union type. Yes, that's very counterintuitive.
If I wanted an immutable list head in the second case, I would have needed to write: def readonly rl : readonly list 'a But this is good. You're all at least beginning to see why dealing with mutability is one confusing headache after another for the programmer. Wouldn't it be nice if functional code could handle systems problems? Then we wouldn't need this awful BitC#-ing language. :-) shap On Thu, Aug 8, 2013 at 4:53 PM, Glen Anderson <[email protected]>wrote: > On 8 August 2013 23:12, Jonathan S. Shapiro <[email protected]> wrote: > > Now for the first sleeping dragon. > > > > What is the difference, if any, between: > > > > union rolist 'a is > > readonly cons { car: 'a; cdr: rolist 'a } > > nil; > > > > def rl : rolist 'a; > > > > > > and > > > > union list 'a is > > cons { car: 'a; cdr: list 'a; } > > nil > > > > def rl : readonly list 'a; > > > > > > That is: how are the two definitions of /rl/ different, behaviorally? > > > > Hint: it has nothing to do with nil, since lacking any fields nil is > > inherently readonly. > > In the first case the list head is mutable but it's fields are not so > while we cannot alter the list through rl.cdr we can assign a > different list head to rl, destroying the old list head and leaving a > dangling list. > > In the second case the readonly annotation applies only to the list > head since it is not transitive. While we cannot assign a new list > head to rl as we can in the first case we are able to alter any part > of the list after the list head. > _______________________________________________ > bitc-dev mailing list > [email protected] > http://www.coyotos.org/mailman/listinfo/bitc-dev > >
_______________________________________________ bitc-dev mailing list [email protected] http://www.coyotos.org/mailman/listinfo/bitc-dev
