[Grace-core] some thoughts on structural types & pattern matching

James Noble kjx at ecs.vuw.ac.nz
Fri Sep 9 22:36:21 PDT 2011


> I would ask: are they really the same?  I would have expected, for example, that a variable would have a method to generate an assignment to that variable, whereas a constant would not.  So, if the type are the same, the programmer should stop and think: are these really two different implementation of the SAME type,a re are they different types, and if so, what, abstractly, is the difference?

well, in the code I looked at they are the same.
And I think it is not an unreasonable piece of code to write.
In the absence of multimethods, cases may also be used
as an alternative to double-dispatch - and again, each side
of the dispatch may have the same (or very similar) types.

> This is one of the reasons that I have been opposed to typecase.  You appeased me by saying that typecase would be defined in terms of message sends.
> If that is the case, then I don't see how it can do anything that could not be done by message send.  Is it no longer the case that case is defined in terms of message-send?

The case statement itself can be defined in terms of message sends to "pattern" objects.
We've a good idea now about how that side of it can work - the only detail remaining is
that we'll need some kind of collection or tuple or multiple return values to handle the
extraction of multiple values.

> Note, however, that once a program sends a reflexive message, all bets are off.  The result of the program can depend on the presence or value of any annotation, or on the name of any variable, or on many other things that change the structure of a program.  That's why it's so important to distinguish reflexive and non-reflexive messages.  

Right. And so some patterns - especially those related to types or "classes" - 
will need to be defined by reflexive messages. 

> Being able to trap Message not understood errors is one kind of reflection.

yep - and quite a powerful one. 

>  Being able to ask whether or not a message will be understood is another.  Typecase does the latter, does it not?


yep, that's pretty much it. 

> 
> This discussion further convinces me that typecase is a bad idea in an OO Language.

well, yes...

James


More information about the Grace-core mailing list