[Types-sig] const (was: PyDL RFC 0.02)

skaller skaller@maxtal.com.au
Fri, 31 Dec 1999 05:17:34 +1100


Paul Prescod wrote:
> 
> skaller wrote:
> >
> > ...
> >         I know, but that is my point: it isn't consistent
> > with a model in which checking is applied to _names_:
> 
> Yes it is. Readonly-ness is part of an object's interface.

	No. Objects don't HAVE interfaces. NAMES have interfaces.
Access to the object is constrained by the interface associated
with the name. A standard dictionary could, if we had some kind
of const, be accessed via two names: the first, allowing only
read access, and the second read and write. 

	An object can be 'compatible' with many interfaces.
It can only be _accessed_ via a name, through the declared
interface. Two names, two interfaces. One object.
your model!

	Example: an object is accessed as a Sequence.
Same object is also accessed by a different name bound
to a different interface, as List. Should work across
function call boundaries to support protocol based 
polymorphism:

	decl x as List
	def f(y as Sequence): ..
	f(x) # should be OK: a List 'is a' Sequence

	So: 'const' in an interface is an access control.
Perhaps object bound to the name with an interface is immutable,
and perhaps not: immutability is a _runtime_ property.
'const' is a compile time one. Objects exist at run time.
Names are bound to interfaces at compile time.

 We could make
> ReadOnlyMapping types, ReadOnlyFile types, ReadOnlyList types,
> ReadOnlyBankAccount types and so forth. It makes more sense to me,
> however, to separate out ReadOnly-ness because it is so pervasive. But
> not for version 1.

	No. If you want an 'immutable dictionary', you need a 
new type. I mean, an actual new Python run-time type object
with different 'methods' defined. The properties of an object
of a certain type are entirely a run time matter. The static
type system doesn't enter into it. Interfaces do not change
the type of an object. They restrict how the object can be accessed.
If you 'see' something as an Immutable Mapping,
you cannot insert a new key: the static type checker would not
let you. This prevents a run time error; but if the object
were a standard dictionary, the static type system will
_still_ stop you accessing the object as a dictionary.

'Seeing is not being'-ly yours.
-- 
John Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850