[Grace-core] some thoughts on structural types & pattern matching
James Noble
kjx at ecs.vuw.ac.nz
Mon Sep 12 04:08:02 PDT 2011
>>> 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.
>
> So it should be flagged as "Meta" ?
ay, there's the rub - that's what we're trying to decide.
The simplest thing that could possible work in an (un/dynamically) typed language
would be to give every object a match( key ) method, which returns a Boolean if the
object conceptually should "match" the "key", and an "extract" method that returns
a tuple for any destructuring binding.
class Object {
method match( k ) { k == "Object" }
method extract { [] } // empty typle
}
class Point { x, y ->
method match( k ) { (k == "Point") || {super.match( k )} }
method extract { [x,y] }
}
where's the meta in that?
is there still meta-ness if the class form somehow generates the "match" method (as it does with ==)
James
More information about the Grace-core
mailing list