Skip to content

Instantly share code, notes, and snippets.

@pcwalton
Created July 15, 2010 19:10
Show Gist options
  • Save pcwalton/477373 to your computer and use it in GitHub Desktop.
Save pcwalton/477373 to your computer and use it in GitHub Desktop.
[11:54am] pcwalton:
preliminary thoughts as to how to implement mutable:
[11:55am] pcwalton:
all values except "true" lvalues are immutable
[11:55am] pcwalton:
a true lvalue is defined as the LHS of an "="
[11:57am] pcwalton:
or things that behave like the LHS of an "=", including field names in records, elements in a tuple constructor, the "@" operator for constructing boxes
[11:58am] pcwalton:
this implies that mutable values are only ever constructed by assigning immutable values to them
[11:59am] pcwalton:
which means we never have explosions of TY_mutable
[11:59am] pcwalton:
(although I'd still prefer it if it were a separate bit)
[12:00pm] pcwalton:
this also suggests that the "mutable" tycon will go away, being replaced with "mutable" annotations in true-lvalue positions
[12:02pm] pcwalton:
so we have rec(foo=1, bar=2, mutable baz=3); tup(1, mutable 2, 3); @ mutable 5
[12:03pm] pcwalton:
but not "mutable 3 + mutable 5" (nonsense, since "mutable" is not in a true lvalue position here)
[12:03pm] dherman:
this sounds like it's on the right track
[12:03pm] pcwalton:
or let int x = mutable 3; (again nonsense, since the RHS of an assignment is not a true lvalue)
[12:06pm] pcwalton:
also forbidden: "@ mutable mutable 5" (you only get one annotation, it's not a tycon)
[12:08pm] graydon joined the chat room.
[12:08pm] graydon was promoted to operator by ChanServ.
[12:08pm] pcwalton:
but it is a part of the type, which means that you can make a vector class and "myvec[mutable int]" will do the right thing
[12:08pm] froystig:
graydon: :(
[12:08pm] pcwalton:
vector type, not class, sorry :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment