You are right. But then I don't see your problem.  By the way, your code should 
probably be:

struct S
is
  const i    : int32
  const next : nullable S

boxed struct Container
is
  mutable s : nullable S;  // <--- Otherwise you can't represent a zero-length 
list.

def S_length(s : nullable S) // <--- Or else a type error, right?
in
   case s in
   null       => 0:int32
   otherwise  => 1 + S_length(s.next);

def f()
in
  let container = Container(S(5, null))  //  container-->[*]-->[5, null]
      chain = S(4, container.s)          //  chain-->[4, *]----^
      len = S_length(chain)              // returns 2 : 
  in
     container.s := S(6,S(7,null))       //  container-->[*]-->[6, *]-->[7, 
null]
                                         //  chain-->[4, *]-->[5, null]

Notice, that the last assignment does not change the value of S(5, null). As 
you mentioned, they are copy-compatible.

PKE

________________________________________
From: [email protected] [[email protected]] On Behalf Of 
Jonathan S. Shapiro [[email protected]]
Sent: Wednesday, March 23, 2011 10:26 PM
To: Discussions about the BitC language
Subject: Re: [bitc-dev] Mutability, again

On Wed, Mar 23, 2011 at 4:22 PM, Pal Engstad 
<[email protected]<mailto:[email protected]>> wrote:
I'm not clear on what exactly const and mutable means here...

Sorry. That seems to be an inherent hazard when discussion mutability.

..., but shouldn't that be two type errors?

I don't think so. I think it's one type error resulting from a typo. See below.


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)
                          ~~~~~~~
                          Type Error: container.s is mutable, but argument 2 in 
the constructor is const.

Nope. The const-ness of the passed argument doesn't matter, because this is a 
copy boundary. The actual parameter here ans the formal parameter are copy 
compatible.


     len = S_length(chain)
 in
    container.s.next = S(6,S(7,null))
    ~~~~~~~~~~~~~~~~~~~~
    Type Error: Trying to mutate a const struct member.

This is the typo. The line should read "container.s" rather than 
"container.s.next". My apologies!


shap


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

Reply via email to