[M3devel] Resummary of tagged reference proposals

hendrik at topoi.pooq.com hendrik at topoi.pooq.com
Tue Jun 2 17:52:47 CEST 2009


On Tue, Jun 02, 2009 at 04:33:49PM +0200, Darko wrote:
> Probably because some union fields disappear and you can't work out  
> statically if a field access is valid.

That's the problem with variant records in Pascal.  I don't like them 
either.  They're not what I'm talking about.  If you have a value of 
type UNION(A, B) you don't get to use an operation on it just because 
the operation happens to be valid on A.

> Maybe you chose the wrong name  
> for your type, because they are actually just dynamically typed values  
> rather than unions.

The unions I'm talking about are disjount unions, the things the 
category theorists oftern call coproducts.  They are dual to Cartesion 
products (which are provided in Moduls 3).  They are type-secure.

My unions comprise a finite number of other types, which means that in 
one place you can see everything that can happen to them.  You don't run 
the risk that somewhere else someone sticks more alternatives into your 
type by inheriting form it.  (this can be a curse or a blessing, 
depending on how your code is organised.  It tends to be awkward to do 
object-oriented code with these unions, just as it's awkward 
using objects and inheritance when you really want unions)

> Maybe you should have called them 'overlays'

I'm not taking about interpreting physical storage in multiple different 
ways.  I'm not talking about tools to store a REAL and fetch an INTEGER 
in order to cut it up with maske to get at the exponent and mantissa.
That's UNSAFE.

I'm talking about a type-safe alternative mechanism in data structures.
One which is more efficient is some circumstances that the one 
traditionally embedded in Modula 3 (else we wouldn't be having this 
discussion), but less efficient in others (such as unions of huge 
records).

But what I'd like to know is why they are considered an anathema instead 
of just an alternative not taken.  Perhaps way back then they were 
talking about different language features.  But treating them as 
anathema seems to have poisoned thinking about any kind of remotely 
similar feature, even type-safe ones.

-- hendrik

> 
> On 02/06/2009, at 1:23 PM, hendrik at topoi.pooq.com wrote:
> 
> >On Tue, Jun 02, 2009 at 08:51:31PM +1000, Tony Hosking wrote:
> >>Union types are anathema to the design of the Modula-3 type system.
> >
> >So I have heard.  But I don't understand why.  Certainly
> >variant records a la Pascal would be for security reasons.
> >Did they get tarred with the same brush?  Or were unions
> >considered unnecessary once the language had objects and
> >inheritance?
> >
> >-- hendrik
> 



More information about the M3devel mailing list