[Types-sig] updated proposal (fwd)
skaller
skaller@maxtal.com.au
Thu, 06 Jan 2000 23:46:26 +1100
scott wrote:
> If I declare somevar as having type 'Any' it means that it is the Any
> type (which in itself doesn't enforce anything other than the variable
> cannot be used in a way that asserts a particular type). When
> something is not declared, it can be deduced from a relatively
> predictable algorithm, but that deduced type is one which allows the
> more permissive 'one of a or b or ... or n'. Declared types seem more
> useful as 'always any of a or b or ... or n' to me. If we wanted the
> 'one of...' behavior in type declarations, I guess I'd be more inclined to
> call that 'xor' than 'or'. Given a choice between the two, I'd prefer
> the 'always any of...' semantics.
The question is not a matter of your personal choice
but logic/mathematics.
Consider a function:
f : Int or String -> Int or String
The function is correct only if it accepts MORE inputs
than the static declaration.
For the return, it is the other way around: the function
must return LESS than the specified types: for example,
always an Int would be OK. But returning a float
would not be.
So, when type checking the FUNCTION, the interpretation
of the static type declarator for the argument and
the return value is different. [In fact, dual: the comparison
is reversed]
On the other hand, checking a _call_,
as opposed to a function: what can be passed in is LESS
than the specification. But the client can apply a procedure
to the return value that works for MORE types than the specification.
My point: the 'behaviour' of a static interface declaration
depends on context. There is no single interpretation.
--
John (Max) 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